cicorias
3/27/2017 - 7:04 PM

Sharing a unix socket between a Docker container and it's host

Sharing a unix socket between a Docker container and it's host

FROM ubuntu

RUN apt-get update
RUN apt-get install -y socat

VOLUME /foo

CMD socat UNIX-LISTEN:/foo/bar.sock -
  • 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