此问题在此处已有答案:
Deploying a minimal flask app in docker - server connection issues(8个答案)
昨天关闭。
cd8eeeb21b2d flask-test-flask-app "bash ./export.sh" 14 seconds ago Up 14 seconds 0.0.0.0:5001->5000/tcp, :::5001->5000/tcp flask-container
对接合成
version: '3.8'
services:
flask-app:
container_name: flask-container
restart: always
build: .
volumes:
- '.:/app'
ports:
- 5001:5000
我收到的错误
curl -X获取http://本地主机:5001/测试
接收失败:连接被对等方重置
1条答案
按热度按时间olqngx591#
您已将主机的端口
5001
转发/发布到容器的端口5000
。因此,您必须在 * 主机 * 上访问的端口是5001
,从而将完整命令发送到curl -X GET http://localhost:5001/test
。Docker文档关于此:https://docs.docker.com/config/containers/container-networking/#published-ports