Windows + Docker +端口未公开/可访问

时间:2018-01-16 09:42:10

标签: windows docker port

问题:

来自windows主机。端口映射/曝光不起作用。

无法访问容器应用。

curl http://localhost:PORT (127.0.0.1 / 0.0.0.0)
-> Could not get any response

curl http://DOCKER-IP:PORT (127.17.0.1 / 127.17.0.2)
-> Could not get any response

curl http://DOCKER-SUBNET-ADDRESS:PORT (10.0.75.0)
-> Could not get any response

设定:

Windows10主机系统 + Docker容器(带有简单的helloworld python flask app)

Docker容器正在运行。 在docker容器内,flask应用程序的行为符合预期。

繁殖:

  1. 获取hello world repo

    git clone https://github.com/shekhargulati/python-flask-docker-hello-world

  2. 构建并运行docker container

    docker build -t simple-flask-app:latest . docker run -d -p 5000:5000 simple-flask-app --name simple-flask-app

  3. 执行容器&检查瓶正在运行

    docker exec -it simple-flask-app apt-get install curl curl http://127.0.0.1:5000

    - >请参阅200 OK + Flask is running(或类似文字)

  4. 退出泊坞窗容器

    exit

  5. 卷曲你的Windows主机

    curl http://127.0.0.1:5000

    - >请参阅Could not get any response(或类似内容)

6 个答案:

答案 0 :(得分:3)

对我来说,最简单的解决方案是运行:

docker-machine ip default

这将打印IP地址。就我而言,ipconfig不会显示该IP。 我在Windows 7主机上使用Docker 18.03.0-ce进行了测试。

我在这里找到了这个提示:https://www.jhipster.tech/tips/020_tip_using_docker_containers_as_localhost_on_mac_and_windows.html

答案 1 :(得分:2)

我刚刚更改了name参数的顺序,并且它工作正常(在Linux中)。

docker run -d -p 5000:5000 --name simple-flask-app simple-flask-app

答案 2 :(得分:1)

简短解决方案

  1. 运行您的泊坞窗应用 1.1(执行您的泊坞窗并确保您的应用按预期工作)
  2. 在您的Windows主机上

    IPCONFIG

  3. 其中一个公开的IPv4地址可以使用。只要一个接一个地尝试。

    curl http://IPCONFIG-IPv4-TRY-OUT:PORT -> 200 OK + Flask is running

  4. - > Windows上的Docker不会将流量转发到docker容器,如linux / mac所知。

    - >看起来流量被认为是eth0。

答案 3 :(得分:1)

您需要连接到实际运行docker的VM:

通过运行docker-machine ip default找到IP地址并使用该IP连接:

curl http://<ip-address>:5000

答案 4 :(得分:0)

您需要将应用设置为在host ='0.0.0.0'上运行。那就是:

app.run(host='0.0.0.0')

因此,当您运行时:

> docker run -d -p 5000:5000 simple-flask-app --name simple-flask-app
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
* Restarting with stat

然后curl http://localhost:5000起作用。

贷方转到: https://codefresh.io/docker-tutorial/hello-whale-getting-started-docker-flask/

答案 5 :(得分:0)

与烧瓶无关,但最近我遇到了同样的问题。我们的主机需要一个静态IP地址,因此IT更改了一些网络配置。然后,我注意到“控制面板” \“网络”和“ Internet \网络连接”中的vEthernet适配器已禁用。启用此端口后,转发到容器实例似乎又可以工作了。

相关问题