Skip to content

Instantly share code, notes, and snippets.

@salmon5
Forked from christianberg/Dockerfile
Created June 26, 2019 15:18
Show Gist options
  • Select an option

  • Save salmon5/0a822eeab7b9cc5ade1e7acf2da376c0 to your computer and use it in GitHub Desktop.

Select an option

Save salmon5/0a822eeab7b9cc5ade1e7acf2da376c0 to your computer and use it in GitHub Desktop.
Sharing a unix socket between a Docker container and it's host
  • Build the image from the Dockerfile above:
docker build --rm -t cberg-test .
  • Run a container, sharing the host dir /root/foo:
docker run --rm -v /root/foo:/foo cberg-test
  • In another shell, write something to the socket (which was created in /root/foo by the container):
echo 'hello docker' | socat - UNIX-CONNECT:/root/foo/bar.sock
  • See the output of the container in the first shell:
hello docker
FROM ubuntu
RUN apt-get update
RUN apt-get install -y socat
VOLUME /foo
CMD socat UNIX-LISTEN:/foo/bar.sock -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment