Having socket issues with Docker + Echo


Hey Guys,

Hopefully someone can point me in the right direction. I am running Echo from within a docker container and I need the server to listen on a unix socket instead of a tcp port. For that I was able to use the following snippet and connecting to the unix socket from within the container works like a champ.

l, err := net.Listen("unix", "/tmp/echo.sock")
if err != nil {
server.Listener = l

From within the container I can curl and the server answers.

[email protected]:/go/src/gandalfd# curl --unix-socket /tmp/echo.sock http://localhost
[email protected]:/go/src/gandalfd#

The issue I am having is trying to connect to the same socket from the host now. I have mapped the the volume as follows

docker run --rm -v /tmp/echo.sock:/tmp:rw <container_name>:latest

On the host machine when I look within /tmp I do see the socket in there

ls -lah *.sock
total 0
drwxr-xr-x    3 dd  wheel    96B Jun 12 09:30 .
drwxrwxrwt  100 root     wheel   3.1K Jun 12 09:34 ..
srwxrwxrwx    1 dd  wheel     0B Jun 12 09:30 echo.sock
 [email protected] /tmp

When I try to curl the same socket I am not able to connect to it

curl --unix-socket /tmp/echo.sock http://localhost
curl: (7) Couldn't connect to server
 ✘ [email protected]  /tmp

Thank you!


After searching more it seems like this is an issue with Docker Mac Desktop?