Running the following command fails:
sudo docker run -p unix:///tmp/file.sock:44444 -d image_name
Is something wrong with my port forwarding syntax or is a configuration like this not possible?
Running the following command fails:
sudo docker run -p unix:///tmp/file.sock:44444 -d image_name
Is something wrong with my port forwarding syntax or is a configuration like this not possible?
Docker's
-p
syntax won't take a unix socket:One solution would be to:
-p
specification, we'll name it"cont1"
(--name cont1
)-v /tmp/file.sock:/tmp/file.sock
) to have it accessible from within the container--link cont1:cont1
) to be able to connect to itsocat
to route traffic from the unix socket to the"cont1:4444"
endpointI'm not a socat expert, but the address specification you'll need should look like this:
UNIX-LISTEN:/tmp/file.sock,fork,reuseaddr TCP4:cont1:4444
The accepted answer is partially correct however since you can only link directories, which means you need to link the directory of the socket instead of the socket itself.
The following did it for me when I wanted to connect a postgres socket.
docker run -p 5432:5432 -v /run/postgresql:/run/postgresql -d --name postgres postgres
What this does is link the postgres socket file to your host system.