I have a service running in Docker that listens on a Unix Domain Socket, and a client running on the Docker host (a Mac). The client gets a "Connection Refused" error trying to connect.

I'm mapping the volume when I run the server (docker run -it -v /localpath:/var/run myservice) and I see the socket file created in the local dir just fine.

It works fine if I also run the client in Docker (different container instance), or if I run both locally. But if I run one side in Docker and the other locally it fails (I've tried both directions). I thought it might be a uid/gid mismatch but that looks ok, and if I force them to be different I get a permission denied error.

My app is using Java 16's UnixDomainSocketAddress, but I've also tested with a python script (using an AF_UNIX socket) and see the same problem, so it seems like a Docker thing. Any ideas?

1 Answer 1


Sharing (mounting?) Unix sockets between the macos host and the linux vm in which docker containers are run is not possible at this time. Work on this issue has stopped.


  • The linked github issue describes a ssh agent specific workaround that is part of docker now.
  • Other programs are also designed to work over a network as well (like X11 or pulseaudio). Docker containers can see their host at host.docker.internal on docker desktop for mac and windows. I dont know what it is for docker on linux. https://docs.docker.com/desktop/networking/#i-want-to-connect-from-a-container-to-a-service-on-the-host
  • The previous technique can be augmented for other programs that are adamant about using sockets. You can use socat on the host to map a socket on the host to a port on the host. Then use socat inside the container to map the host's port to a socket within the container. However this introduces another process you have to manage. You might need
    • some clever scripting inside the container to run ur program and socat
    • an init system / process manager inside the container
    • or theoretically, u could run socat in its own container, then share the socket between your app's container and socat's container. ive never tried this tho

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.