大网数据广告活动
服务器运维问答

Failed to connect to localhost port 5000: Connection refused with Docker

· 52CE 我爱测

I have build my small Python(flask ) app.Container is here docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4146fd976547 identidock_identidock:latest "/cmd.sh" 5 minutes ago Up 5 minutes 9090/tcp, 9191/tcp agitated…

问题原文

原帖链接 · MikiBelavista · CC BY-SA 3.0

I have build my small Python(flask ) app.Container is here docker ps

CONTAINER ID        IMAGE                          COMMAND             CREATED             STATUS              PORTS                NAMES
4146fd976547        identidock_identidock:latest   "/cmd.sh"           5 minutes ago       Up 5 minutes        9090/tcp, 9191/tcp   agitated_leakey

If I try

curl localhost:5000
curl: (7) Failed to connect to localhost port 5000: Connection refused

I have checked sudo netstat -an | grep -E "5000" unix 3 [ ] STREAM CONNECTED 25000

It is not listeting on 5000. yaml line with ports

  ports:
   - "5000:5000"

If I exec my container

docker exec -it agitated_leakey /bin/bash
uwsgi@4146fd976547:/app$ netstat -ln
bash: netstat: command not found

My Dockerfile

RUN pip install Flask==0.10.1 uWSGI==2.0.8
WORKDIR /app
COPY app /app
COPY cmd.sh /

EXPOSE 9090 9191

Why this happens?

已采纳解答

原帖链接 · user490221 · CC BY-SA 4.0

An alternative issue can be with the mode. In the publish section I had to set the mode explicitly to host and everything worked:

docker service create --name registry --publish published=5000,target=5000,mode=host registry:2

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-03-29)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。