[英]Docker: cannot route docker container port to host
So I have a docker container up running, I tried to route its service port out to the host:所以我有一个 docker 容器正在运行,我尝试将其服务端口路由到主机:
Here is my docker-compose file:这是我的 docker-compose 文件:
version: '3'
services:
ai-recommender-server:
build: .
ports:
- "3518:3518"
When the container is running, I can check it through "docker ps -a"当容器运行时,我可以通过“docker ps -a”进行检查
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ff940601a02f recommender_ai-recommender-server "python server.py" About an hour ago Up About an hour 0.0.0.0:3518->3518/tcp recommender_ai-recommender-server_1
When I tried to access from inside the container:当我尝试从容器内部访问时:
$ docker exec -it ff94 sh
/service # curl http://localhost:3518
{
"message": "AI recommendation system"
}
But when I tried to do this on the host, I got the error "curl: (56) Recv failure: Connection reset by peer"但是当我尝试在主机上执行此操作时,出现错误“curl: (56) Recv failure: Connection reset by peer”
$ curl http://localhost:3518
curl: (56) Recv failure: Connection reset by peer
Can anyone find out what my problem is?谁能找出我的问题是什么?
Since it's python, I think binding to 0.0.0.0
may be missing in your python code由于它是 python,我认为你的 python 代码中可能缺少绑定到0.0.0.0
Something like this inside your python server.py在你的 python server.py 里面有这样的东西
app.run(debug='False',host='0.0.0.0',port=3518)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.