python - 无法在 Windows 上连接到 Docker 上的 Flask 应用程序
问题描述
我有一个烧瓶应用程序(Dash plotly),我想在 Docker 上运行它。我在 Linux 上做了以下事情并成功运行:
- 运行烧瓶应用程序的代码:
app.run_server(debug=True, host='0.0.0.0')
- 在 Dockerfile 中公开端口:
EXPOSE 8050
- 在 Dockerfile 中运行应用程序的代码:
CMD ["python", "./app.py"]
- 从我跑的终端:
sudo docker build -t app .
- 从我跑的终端:
sudo docker run -p 8050:8050 --mount type=bind,source=/,target=/tmp app
它为我提供了 url:0.0.0.0.8050,它工作正常。
但是,当我在 Windows 10 上下载 Docker Toolbox 并执行完全相同的步骤时,它并没有在提供的 url 上启动应用程序。
有谁知道是什么问题?
解决方案
It's because docker isn't running natively on Windows. It's running on a virtual Linux machine on Windows. So, instead of using the 0.0.0.0
, you have to check the IP of the toolbox by using:
docker-machine ls
And then replace 0.0.0.0
with the that ip
Update:
If you want to use the host network, you can use the host mode by --network
host. But please note that port forward will not work.
reference:
推荐阅读
- javascript - iOS (12.1) 中的 WebRTC Safari。连接第二个远程流时,第一个直播暂停
- elasticsearch - Elasticsearch 转义斜线
- nginx - 如何使用 nginx http/2 服务器推送从 API 调用向客户端发送 json 有效负载
- c# - c#电话簿项目的通用方法
- typo3 - TYPO3 - 内容在翻译时显示两次
- python - Python字节转换
- asp.net - 错误异常处理错误,重定向过多
- firebase - Firebase 动态链接不适用于 Firebase 使用电子邮件链接登录(无密码)
- jdbc - 使用 JDBC 将数据帧写入 Postgresql 时出现 java.lang.StackoverflowError
- android - recyclerview中的收藏按钮,没有存储内部数据没有firebase或解析方法,点击适配器