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

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   "/"           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

   - "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
COPY app /app

EXPOSE 9090 9191

Why this happens?

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

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.

can you ssh to docker container and netstat to check if the port is listening. Was docker port 5000 exposed ?

@Dextro67 Take a look at my edit,please.