Can't connect to host-listening UNIX-SOCKET from container/VM

Expected behavior

On OSX Side:
socat -d -d - UNIX-LISTEN:/tmp/.X11-unix/X1,fork
2016/06/15 00:49:02 socat[2062] N reading from and writing to stdio
2016/06/15 00:49:02 socat[2062] N listening on LEN=19 AF=1 “/tmp/.X11-unix/X1”
2016/06/15 00:49:32 socat[2062] N accepting connection from LEN=16 AF=1 “” on LEN=19 AF=1 “/tmp/.X11-unix/X1”
2016/06/15 00:49:32 socat[2062] N forked off child process 2067
2016/06/15 00:49:32 socat[2062] N listening on LEN=19 AF=1 “/tmp/.X11-unix/X1”
2016/06/15 00:49:32 socat[2067] N starting data transfer loop with FDs [0,1] and [6,6]
2016/06/15 00:49:58 socat[2067] N socket 2 (fd 6) is at EOF
2016/06/15 00:49:59 socat[2067] N exiting with status 0
2016/06/15 00:49:59 socat[2062] N childdied(): handling signal 20

On VM/Container Side
socat -d -d UNIX-CONNECT:/tmp/.X11-unix/X1 -
2016/06/15 00:58:22 socat[2127] N opening connection to LEN=19 AF=1 “/tmp/.X11-unix/X1”
2016/06/15 00:58:22 socat[2127] N successfully connected from local address LEN=16 AF=1 “”
2016/06/15 00:58:22 socat[2127] N reading from and writing to stdio
2016/06/15 00:58:22 socat[2127] N starting data transfer loop with FDs [5,5] and [0,1]

Actual behavior

On VM
moby:/tmp/.X11-unix# socat -d -d UNIX-CONNECT:./X1 -
2016/06/15 03:59:28 socat[2784] N opening connection to AF=1 “./X1”
2016/06/15 03:59:28 socat[2784] E connect(5, AF=1 “./X1”, 6): Connection refused
2016/06/15 03:59:28 socat[2784] N exit(1)

On Container
[root@b6bf31098e33 tmp]# socat -d -d UNIX-CONNECT:/tmp/.X11-unix/X1 -
2016/06/15 04:01:00 socat[18] N opening connection to AF=1 “/tmp/.X11-unix/X1”
2016/06/15 04:01:00 socat[18] E connect(3, AF=1 “/tmp/.X11-unix/X1”, 19): Connection refused
2016/06/15 04:01:00 socat[18] N exit(1)

Information

  • the output of:

Docker for Mac: version: mac-v1.11.2-beta15
OS X: version 10.11.5 (build: 15F34)
logs: /tmp/20160615-010451.tar.gz
failure: No error was detected
[OK] docker-cli
[OK] app
[OK] menubar
[OK] virtualization
[OK] system
[OK] osxfs
[OK] db
[OK] slirp
[OK] moby-console
[OK] logs
[OK] vmnetd
[OK] env
[OK] moby
[OK] driver.amd64-linux

Darwin 15.5.0 Darwin Kernel Version 15.5.0: Tue Apr 19 18:36:36 PDT 2016; root:xnu-3248.50.21~8/RELEASE_X86_64 x86_64

Steps to reproduce the behavior

  1. install socat on OSX, VM and/or Container
  2. run socat -d -d - UNIX-LISTEN:/tmp/.X11-unix/X1,fork on OSX
  3. run socat -d -d UNIX-CONNECT:/tmp/.X11-unix/X1 - on VM and/or Container.

socat run on OSX as normal user.
socat run on VM/Container as root.
docker run commando, run both as normal user, or sudo as root with same behavior.

1 Like

I also this problem when mounting volumes with sockets.

Wondering why it works with the docker.sock and not with our own sockets.

Please see the File Types section in the docs at https://docs.docker.com/docker-for-mac/osxfs/#file-types. The docker.sock has a special case with an OS X-side server listening to it. We have plans for generic trans-hypervisor Unix domain socket support (it’s on the roadmap) but we haven’t yet built all necessary components or integrated them into development builds.

The near-term workaround is to use TCP sockets (listening on local interfaces only) with something like socat to pipe through socket files.

Hope this helps,

David

1 Like

Thanks for the help @dsheets. I will do it using TCP sockets.