<p>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.</p>
<p><a href="https://github.com/docker/for-mac/issues/483" rel="nofollow noreferrer">https://github.com/docker/for-mac/issues/483</a></p>
<ul>
<li>The linked github issue describes a ssh agent specific workaround that is part of docker now.</li>
<li>Other programs are also designed to work over a network as well (like X11 or pulseaudio). Docker containers can see their host at <code>host.docker.internal</code> on docker desktop for mac and windows. I dont know what it is for docker on linux. <a href="https://docs.docker.com/desktop/networking/#i-want-to-connect-from-a-container-to-a-service-on-the-host" rel="nofollow noreferrer">https://docs.docker.com/desktop/networking/#i-want-to-connect-from-a-container-to-a-service-on-the-host</a></li>
<li>The previous technique can be augmented for other programs that are adamant about using sockets. You can use <code>socat</code> on the host to map a socket on the host to a port on the host. Then use <code>socat</code> 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
<ul>
<li>some clever scripting inside the container to run ur program and socat</li>
<li>an init system / process manager inside the container</li>
<li>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</li>
</ul>
</li>
</ul>

CC BY-SA 4.0
2022-07-25T23:24:23.640Z
2022-07-26T00:30:35.437Z
2022-07-26T00:30:35.437Z
Hybras
<p>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 &quot;Connection Refused&quot; error trying to connect.</p>
<p>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.</p>
<p>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.</p>
<p>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?</p>

<docker>
Connection Refused to Unix socket in Docker container from host
Eric McNeill
# Connection Refused to Unix socket in Docker container from host

(Asked by: username_0 on 2021-04-09)

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?

**Tags:** docker


---

## 1 answers

### Answer by username_1 on 2022-07-25. Score: 3 | Accepted answer

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.

<https://github.com/docker/for-mac/issues/483>

* 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


---

