2

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?

MikiBelavista
  • 333
  • 2
  • 5
  • 12

2 Answers2

4

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

alexander.polomodov
  • 1,068
  • 3
  • 10
  • 14
user490221
  • 56
  • 1
2

From the docker ps output seems that your port has not been exposed.

$ docker run -d -p 5000:5000 flask-sample-one

Run your container mapping the port and if you still face same issue ssh to the container and use the following command.

netstat -lntp | grep :5000

Seems netstat is not installed in the container. You can run a yum install netstat to install and check.

This guide will help you to verify. Check docker ps output at the end.

Dextro67
  • 343
  • 2
  • 10