可以将docker端口转发到主机容器上的unix文件套接字? [英] Can docker port forward to a unix file socket on the host container?
本文介绍了可以将docker端口转发到主机容器上的unix文件套接字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
运行以下命令失败:
sudo docker run -p unix:///tmp/file.sock:44444 -d image_name
我的端口转发语法有问题,还是这样的配置是不可能的? / p>
解决方案
Docker的 -p
语法不会占用unix套接字: / p>
-p = []:发布容器端口到主机(格式:
ip:hostPort:containerPort | ip :: containerPort |
hostPort:containerPort)
一个解决方案是: / p>
- 在没有任何
-p
规范的情况下运行您的容器,我们将其命名为cont1
(- name cont1
) - 运行第二个容器:
- 绑定安装 unix套接字(
-v /tmp/file.s ock:/tmp/file.sock
)可以从容器中访问 - - link cont1:cont1 )的rel =noreferrer>链接的userguide / dockerlinks /#working-with-links-names能够连接到它
- 运行一个工具,如
socat
将流量从unix套接字路由到cont1:4444
端点
- 绑定安装 unix套接字(
我不是一个socat专家,但您需要的地址规范应如下所示: UNIX-LISTEN:/tmp/file.sock,fork,reuseaddr TCP4:cont1:4444
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:
-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
- Bind mounts the unix socket (
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
这篇关于可以将docker端口转发到主机容器上的unix文件套接字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文