如何从本地网络上的另一台机器访问Docker容器 [英] How to access docker container from another machine on local network
问题描述
我正在使用Windows的Docker(我没有使用使用VM的Docker工具箱),但是无法从本地网络上的另一台计算机上看到我的容器。在我的主机中,一切都很完美,并且运行良好,但是,我希望其他人使用我的容器。
I'm using Docker for Windows( I am not using Docker Toolbox that use a VM) but I cannot see my container from another machine on local network. In my host everything is perfect and runs well,however, I want that other people use my container.
尽管发布了在Docker论坛中的相同问题,答案是不显示它。另外,我一直在这里寻找,但解决方案发现它与在虚拟机中设置网桥选项有关,正如我之前所说,我正在将Docker用于不使用虚拟机的Windows。
Despite being posting the same question in Docker's Forum , The answer was not show it. Plus, I have been looking for here but the solutions found it are about setting up the bridge option in the virtual machine , and as I said before, I am using Docker for windows that no use Virtual machine.
Docker版本命令
Docker version Command
Client:
Version: 1.12.0
API version: 1.24
Go version: go1.6.3
Git commit: 8eab29e
Built: Thu Jul 28 21:15:28 2016
OS/Arch: windows/amd64
Server:
Version: 1.12.0
API version: 1.24
Go version: go1.6.3
Git commit: 8eab29e
Built: Thu Jul 28 21:15:28 2016
OS/Arch: linux/amd64
docker ps -a
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
789d7bf48025 gogs/gogs "docker/start.sh /bin" 5 days ago Up 42 minutes 0.0.0.0:10022->22/tcp, 0.0.0.0:5656->3000/tcp gogs
7fa7978996b8 mysql:5.7.14 "docker-entrypoint.sh" 5 days ago Up 56 minutes 0.0.0.0:8989->3306/tcp mysql
我要使用的容器是gogs在端口5656上工作。
The container I want to use is gogs that is working in the port 5656.
当我使用localhost:5656 y 127.0.0.1:5656可以正常工作,但是当我使用来自以下位置的我的本地网络IP(192.168.0.127)时
When I use localhost:5656 y 127.0.0.1:5656 work properly, but when I use My local network IP (192.168.0.127) from other machine the container is unreachable.
预先感谢。
推荐答案
当我为Windows安装Docker时,它会创建一个名为 vEthernet(DockerNAT)的网络(通常使用ip 10.0.75.1)
When I installed Docker for Windows, it creates a network called vEthernet (DockerNAT) (Usually with the ip 10.0.75.1)
我的本地计算机有一个名为 local area connection 的网络,其IP地址为192.168.0.172(使用该IP地址,我试图从其他PC上进行访问)。
My local machine had a network called local area connection with the ip 192.168.0.172(With this ip I was trying to access from other PCs).
到目前为止,我的本地计算机有两个网可以使用Conections,因此我转到控制面板> 网络和共享中心> 更改适配器设置,我选择了两个网络,然后右键单击了所选的网络添加到网桥。这就创建了一个名为 Ethernet 的第三个网络。
So far, My local Machine had Two networks Conections so that I went to Control panel > NetWork and Sharing center > Change Adapter Settings I selected the two networks and I right-click selected Add to bridge. That create a Third network called Ethernet.
此时,我不知道 Ethernet 的Ip是多少。网络,因此我执行了ipconfig命令,该命令向我显示了IP 192.168.0.17(本地连接和 vEthernet(DockerNAT)的设置消失了,并且ips 10.0.75.1和192.168 .0.172停止工作)。
At this point, I didnt know what was the Ip of Ethernet network, so I executed ipconfig command that show me the ip 192.168.0.17(The settings of local area connection and vEthernet (DockerNAT) disappeared and the ips 10.0.75.1 and 192.168.0.172 stop working).
使用这个新IP(192.168.0.17),我从网络中的其他计算机尝试了一下,最后我可以访问容器(192.168.0.17:5656)。
With this new ip (192.168.0.17) I tried from other machine in the network and finally I could access to the container(192.168.0.17:5656).
这篇关于如何从本地网络上的另一台机器访问Docker容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!