在Windows上使用Docker进行网络连接 [英] Networking with Docker on Windows
问题描述
我使用本官方指南在Windows 7机器上设置Docker:
I used this official guide to set up Docker on a Windows 7 machine:
https://docs.docker.com/windows/started/
我成功地从泊坞窗集线器,我可以运行我自己的码头图像。
I successfully pulled an image from the docker hub and I can run my own docker image.
不,我试图在Windows上运行和访问与docker的Web服务器。显然,在 boot2docker
之后,我无法通过我习惯的方式到达我的docker容器。
No I am stuck trying to run and access a webserver with docker on Windows. Apparently, behind boot2docker
I can't reach my docker container the way I was used to.
一旦我添加 -p 3007:80
到 docker run
命令,端口转发显示在容器列表中( docker ps
)as 0.0.0.0:3007 - > 80
。并且与 -p 127.0.0.1:3007:80
我得到一个更有意义的ip地址。然而,我不能使用Windows主机上的浏览器到达容器。
Once I added -p 3007:80
to the docker run
command, the port forwarding showed up in the container list (docker ps
) as 0.0.0.0:3007 -> 80
. And with -p 127.0.0.1:3007:80
I get a more meaningful ip address. I cannot, however, reach the container with a browser on the Windows host.
此外, docker inspect
不显示运行容器的IP地址(也似乎是错误的)。
Moreover, docker inspect
does not reveal an ip address for the running container (which also seems wrong).
我还尝试了 - net = host
无效。
推荐答案
随着Docker Toolbox的介绍,事情发生了一些变化。现在您不直接与 boot2docker
直接交互,而是使用 docker-machine
。虽然 boot2docker
仍然存在,但VM不再有CLI-Tool。它被Docker Machine取代。
Things changed a little with the introduction of Docker Toolbox. Now you do not directly interact with boot2docker
, but instead use docker-machine
. Although boot2docker
still exists as VM there is no CLI-Tool any longer. It was replaced by Docker Machine.
因此,您应该能够通过键入以下命令来获取VM的IP地址: docker-machine ip<机器名称>
。如果您有默认安装,您的计算机名称将为 default
。
Thus you should be able to get hold of the VM's IP address by typing: docker-machine ip <machine-name>
. If you do have the default installation your machine name will be default
.
使用 docker -machine active
您可以查看当前活动的VM。使用该名称,您还可以使用 docker-machine inspect< machine-name>
。
With docker-machine active
you can have a look which VM is currently active. With that name you can also use docker-machine inspect <machine-name>
.
您可以找到更多关于Docker Machine在官方文档。
You can find more about Docker Machine in the official docs.
这篇关于在Windows上使用Docker进行网络连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!