Can docker port forward to a unix file socket on the host container?

前端 未结 2 1713
再見小時候
再見小時候 2020-12-29 23:20

Running the following command fails:

sudo docker run -p unix:///tmp/file.sock:44444 -d image_name

Is something wrong with my port forwardin

2条回答
  •  爱一瞬间的悲伤
    2020-12-30 00:08

    Docker's -p syntax won't take a unix socket:

    -p=[]      : Publish a container᾿s port to the host (format:
                 ip:hostPort:containerPort | ip::containerPort |
                 hostPort:containerPort)
    

    One solution would be to:

    • Run your container without any -p specification, we'll name it "cont1" (--name cont1)
    • Run a second container which:
      • Bind mounts the unix socket (-v /tmp/file.sock:/tmp/file.sock) to have it accessible from within the container
      • Links to the first container (--link cont1:cont1) to be able to connect to it
      • Runs a tool such as socat to route traffic from the unix socket to the "cont1:4444" endpoint

    I'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

提交回复
热议问题