Ben*_*itz 2 windows port docker
问题:
从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
Run Code Online (Sandbox Code Playgroud)
设定:
Windows10主机系统+ Docker容器(带有简单的helloworld python flask应用程序)
Docker容器正在运行。在Docker容器内,flask应用程序的行为符合预期。
再生产:
获取你好世界回购
git clone https://github.com/shekhargulati/python-flask-docker-hello-world
构建并运行Docker容器
docker build -t simple-flask-app:latest .
docker run -d -p 5000:5000 simple-flask-app --name simple-flask-app
exec进入容器并检查烧瓶是否正在运行
docker exec -it simple-flask-app
apt-get install curl
curl http://127.0.0.1:5000
->查看200 OK + Flask is running(或类似这样的文字)
退出Docker容器
exit
在Windows主机上卷曲
curl http://127.0.0.1:5000
->看Could not get any response(或类似的东西)
Yog*_*ani 10
您需要将应用程序设置为在 host='0.0.0.0' 上运行。那是:
app.run(host='0.0.0.0')
Run Code Online (Sandbox Code Playgroud)
所以当你运行时:
> 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
Run Code Online (Sandbox Code Playgroud)
然后curl http://localhost:5000工作。
归功于:https : //codefresh.io/docker-tutorial/hello-whale-getting-started-docker-flask/
我只是更改了 name 参数的顺序并且它起作用了(在 Linux 中)。
docker run -d -p 5000:5000 --name simple-flask-app simple-flask-app
Run Code Online (Sandbox Code Playgroud)
小智 7
对我来说,最简单的解决方案是运行:
docker-machine ip default
Run Code Online (Sandbox Code Playgroud)
这将打印一个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
简短的解决方案
在您的 Windows 主机上
ip配置
这些公开的 IPv4 地址之一将起作用。只要一一尝试就可以了。
curl http://IPCONFIG-IPv4-TRY-OUT:PORT
-> 200 OK + Flask is running
-> Windows 上的 Docker 不会将流量转发到 linux/mac 中已知的 docker 容器。
-> 看起来流量已转发到 eth0。
| 归档时间: |
|
| 查看次数: |
3786 次 |
| 最近记录: |