加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

访问Windows主机上的docker容器URL

发布时间:2020-12-14 04:25:37 所属栏目:Windows 来源:网络整理
导读:警告#1:我已经阅读了 this answer,this answer和一个miriad其他答案/帖子,我仍然无法让它工作. 警告#2:我是码头工的新手,所以我可能会错过一些非常简单的东西. 我在Windows上运行Docker,运行this ELK image,我使用此命令启动: sudo docker run -p 5601:56
警告#1:我已经阅读了 this answer,this answer和一个miriad其他答案/帖子,我仍然无法让它工作.

警告#2:我是码头工的新手,所以我可能会错过一些非常简单的东西.

我在Windows上运行Docker,运行this ELK image,我使用此命令启动:

sudo docker run -p 5601:5601 -p 9200:9200 -p 5000:5000 -it --name elk sebp/elk

我正在尝试从Windows上运行的浏览器访问端口5601和9200,并且我一直在连接超时.这就是我所做的:

>我相信docker run命令(上面)已经将端口5601和9200从容器转发到docker主机(boot2docker VM),所以应该没问题.
>我通过运行docker inspect $(docker ps -q)|获得了elk docker container IP在docker CLI上使用grep IPA.结果是172.17.0.9.然后我运行卷曲172.17.0.9:5601并卷曲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 192.168.99.100,但无法得到响应.我尝试在Windows中放宽防火墙规则(只是为了再次踢),我一无所获.

我错过了什么?

解决方法

实际上在Windows中将会运行一个Ubuntu VM,最重要的是只有你的容器被托管,所以只有你不能直接访问它

即使我遇到同样的问题,我按照以下步骤解决了我的问题

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

现在我能够从网络中的任何系统访问容器:)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读