从docker容器连接到主机套接字
我有下面的docker容器从docker容器连接到主机套接字,docker,networking,wsgi,Docker,Networking,Wsgi,我有下面的docker容器 FROM ubuntu:16.04 RUN apt-get update && apt-get install -y curl net-tools netcat nmap CMD /bin/bash 我使用卷/tmp映射运行它 从主机上,我在/tmp中创建了一个套接字。我使用ncat进行了测试,连接可以从主机上工作。但是,它在docker容器中不起作用 ncat -U /tmp/uwsgi.sock Ncat: Connection refused.
FROM ubuntu:16.04
RUN apt-get update && apt-get install -y curl net-tools netcat nmap
CMD /bin/bash
我使用卷/tmp
映射运行它
从主机上,我在/tmp
中创建了一个套接字。我使用ncat
进行了测试,连接可以从主机上工作。但是,它在docker容器中不起作用
ncat -U /tmp/uwsgi.sock
Ncat: Connection refused.
我怎样才能做到这一点
权限:
$ ls -al /tmp/uwsgi.sock
srwxrwxrwx 1 user wheel 0 Jun 19 23:53 /tmp/uwsgi.sock
Ncat:连接被拒绝。
表示对等方已关闭连接,因此容器中的您无法链接到它
给你举个例子:
docker主机部件:
shubuntu1@shubuntu1:~$ ncat -lU /tmp/test.sock
hello
world
shubuntu1@shubuntu1:~$ docker run -it -v /tmp:/tmp ubuntu /bin/bash
root@01f724409cec:/# apt-get update && apt-get install -y curl net-tools netcat nmap
root@01f724409cec:/# ncat -U /tmp/test.sock
hello
world
命令将容器与另一个ssh会话绑定:
shubuntu1@shubuntu1:~$ ncat -lU /tmp/test.sock
hello
world
shubuntu1@shubuntu1:~$ docker run -it -v /tmp:/tmp ubuntu /bin/bash
root@01f724409cec:/# apt-get update && apt-get install -y curl net-tools netcat nmap
root@01f724409cec:/# ncat -U /tmp/test.sock
hello
world
容器部件:
shubuntu1@shubuntu1:~$ ncat -lU /tmp/test.sock
hello
world
shubuntu1@shubuntu1:~$ docker run -it -v /tmp:/tmp ubuntu /bin/bash
root@01f724409cec:/# apt-get update && apt-get install -y curl net-tools netcat nmap
root@01f724409cec:/# ncat -U /tmp/test.sock
hello
world
当您输入hello
,world
时,您可以在任何一侧看到,另一侧也可以看到
但如果关闭docker主机端的unix套接字:
shubuntu1@shubuntu1:~$ ncat -lU /tmp/test.sock
hello
world
^C
shubuntu1@shubuntu1:~$
然后再次将其连接到容器侧:
root@01f724409cec:/# ncat -U /tmp/test.sock
hello
world
^C
root@01f724409cec:/# ncat -U /tmp/test.sock
Ncat: Connection refused.
它将显示
连接拒绝
您能否提供有关如何创建套接字以及从主机和容器内部运行的所有命令的详细信息。