Unix socket on bind mount

If I bind mount a directory when I start my linux container, and then create a unix domain socket within that mount inside the container:

ubuntu@docker-desktop:~$ socat unix-listen:./test.sock,fork STDOUT
^Z
[1]+ Stopped socat unix-listen:./test.sock,fork STDOUT
ubuntu@docker-desktop:~$ bg

and then look at it:

ubuntu@docker-desktop:~$ ls -l |grep test
ls: cannot access ‘test.sock’: Invalid argument
s??? ? ? ? ? ? test.sock

If I do the same on the container’s file system instead of on the mount:

ubuntu@docker-desktop:/tmp$ socat unix-listen:./test.sock,fork STDOUT
^Z
[2]+ Stopped socat unix-listen:./test.sock,fork STDOUT
ubuntu@docker-desktop:/tmp$ bg
[2]+ socat unix-listen:./test.sock,fork STDOUT &
ubuntu@docker-desktop:/tmp$ ls -l
total 0
srwxr-xr-x 1 ubuntu ubuntu 0 Jul 23 20:13 test.sock

Does anyone know why this is?

Thanks!

Hello!
The issue you’re encountering is likely due to the way bind mounts handle file permissions and attributes. When you create a Unix domain socket within a bind-mounted directory, the host filesystem might not fully support the special file types or attributes required for the socket, leading to the “Invalid argument” error.

In contrast, creating the socket directly on the container’s filesystem works because the container’s native filesystem fully supports these attributes.

To work around this, you can try creating the socket on the container’s filesystem and then move it to the bind-mounted directory, or use a named volume instead of a bind mount for better compatibility with special file types like Unix domain sockets.

Thanks @thomas195mancilla . I actually got to the same solution last night. I appreciate the details in your reply!