访问Windows主机上的docker容器URL [英] Accessing a docker container URL on Windows host
问题描述
警告#1 :我已阅读这个答案,这个答案,以及一个miriad的其他答案/帖子,我仍然无法让它工作。
Caveat # 1: I've read this answer, this answer, and a miriad other answers/posts and I still can't get it to work.
注意事项#2 :我是docker的新手,所以我可能缺少一些非常简单的东西。
Caveat # 2: I'm new to docker, so I'm probably missing something really simple.
我在Windows上运行Docker,并且具有我运行的这个ELK图像这个命令:
I'm running Docker on Windows, and have this ELK image running which I launched with this command:
sudo docker run -p 5601:5601 -p 9200:9200 -p 5000:5000 -it --name elk sebp/elk
我正在尝试从Windows上运行的浏览器访问端口 5601
和 9200
,我保持获取连接超时。以下是我所做的:
I'm trying to access ports 5601
and 9200
from a browser running on Windows, and I keep getting a connection timeout. Here's what I've done:
- 我相信
docker运行
命令)将端口5601和9200从容器转发到docker主机(boot2docker VM),这样应该是正常的。 - 我通过运行
docker inspect $(docker ps -q)获得了麋鹿码头容器IP grep IPA
在docker CLI上。原来是172.17.0.9
。然后我运行curl 172.17.0.9:5601
和curl 172.17.0.9:9200
。我能够从这些URL中获得适当的HTML响应。这使我能够验证docker容器/主机中的东西是否正常运行。 - 然后我通过运行
docker-machine ip default
得到docker主机的IP。原来是192.168.99.100。我相信这是我需要从Docker主机访问elk容器(在这种情况下为Windows),因为容器的端口转发已经设置。有了这个IP,我试着去http://192.168.99.100:5601
和http://192.168.99.100:9200
我得到ERR_CONNECTION_TIMED_OUT
。我也尝试使用IE,甚至https
进行踢,还没有运气。 - 我也尝试从DOS ping ping
192.168.99.100
,但无法得到响应。我试着在Windows中放松防火墙规则(只是为了再次踢),我什么都没有。
- I believe the
docker run
command (above) is forwarding ports 5601 and 9200 from the container to the docker host (boot2docker VM) already, so that should be fine. - I got the elk docker container IP by running
docker inspect $(docker ps -q) | grep IPA
on the docker CLI. This turned out to be172.17.0.9
. I then rancurl 172.17.0.9:5601
andcurl 172.17.0.9:9200
. I was able to get proper HTML responses from those URLs. This allowed me to verify things were running properly in the docker container/host. - Then I got the docker host's IP by running
docker-machine ip default
. This turned out to be 192.168.99.100. I believe this is all I need to access the elk container from the docker host (Windows in this case), since port forwarding for the container was already set. With that IP, I tried going tohttp://192.168.99.100:5601
andhttp://192.168.99.100:9200
and I getERR_CONNECTION_TIMED_OUT
. I also tried using IE, and evenhttps
for kicks, and still no luck. - I also tried pinging
192.168.99.100
from DOS, but was unable to get a response. I tried relaxing the firewall rules in Windows (just for kicks again) and I got nothing.
我缺少什么?
推荐答案
实际上在windows里会有一个Ubuntu的VM会运行,只有你的容器才被托管,所以只有你将无法直接访问
actually in windows there will be a Ubuntu VM will be running, on top of that only your containers are hosted so only you won't be able to access it directly
即使我面对同样的问题,我按照以下步骤解决我的问题
Even i faced that same problem and i followed the below steps to solve my problem
1. Enabled routing as told in the above post
2. Added a port forwarding from windows host to Ubuntu host where the containers are hosted by using below command
netsh interface portproxy add v4tov4 listenport=4422 listenaddress=192.168.1.111 connectport=3128 connectaddress=192.168.0.33
a. Here 192.168.1.111 is my windows host ip address and 4422 is the port to where other machines in same network will call
b. Here 192.168.0.33 is the ubuntu host where containers are hosted and 3128 is the ubuntu host port which is mapped to the container
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED
STATUS PORTS NAMES
090af3e0c7a4 sameersbn/squid:3.3.8-5 "/sbin/entrypoint.sh" 6 hours ag
o Up 5 hours 0.0.0.0:3128->3239/tcp squid
3. Then I added firewall to unblock inbound and outbound traffic for 4422 port in my windows host
现在我可以从网络中的任何系统访问容器:)
Now I was able to access the container from any system in the network :)
这篇关于访问Windows主机上的docker容器URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!