Gunicorn Flask application in Docker Container not getting Exposed

The application inside the container is inaccessible from the outside i.e if I exec into the docker container and do

curl localhost:5000 

it works correctly but not on the browser in my computer i get error : This site cant be reached

My Dockerfile:

# Use an official Python runtime as a parent image
FROM python:3.7-slim

# Set the working directory to /app
WORKDIR /web-engine

# Copy the current directory contents into the container at /app
COPY . /web-engine

# Install Gunicorn3
RUN apt-get update && apt-get install default-libmysqlclient-dev gcc -y

# Install any needed packages specified in requirements.txt
RUN pip3 install --trusted-host -r requirements.txt

# Make port 5000 available to the world outside this container

# Define environment variable
ENV username root

# Run when the container launches
CMD gunicorn --workers 4 --bind application:app --threads 1

UPON executing docker in this way:

sudo docker run -e password=$password -p 5000:5000 $reg/web-engine:ve0.0.2

I get the following output:

[2019-09-08 11:53:36 +0000] [6] [INFO] Starting gunicorn 19.9.0
[2019-09-08 11:53:36 +0000] [6] [INFO] Listening at: (6)
[2019-09-08 11:53:36 +0000] [6] [INFO] Using worker: sync
[2019-09-08 11:53:36 +0000] [9] [INFO] Booting worker with pid: 9
[2019-09-08 11:53:36 +0000] [10] [INFO] Booting worker with pid: 10
[2019-09-08 11:53:36 +0000] [11] [INFO] Booting worker with pid: 11
[2019-09-08 11:53:36 +0000] [12] [INFO] Booting worker with pid: 12

So as you can see I’m mapping port 5000 of the container to port 5000 of my computer but localhost:5000 is not working

Therefore i tried everthing the same but with the development server of Flask
with the following change in My dockerfile


CMD gunicorn --workers 4 --bind application:app --threads 1


CMD python3.7

and IT WORKED; I goto localhost:5000 and see the application is working

There is nothing wrong with the application. I suppose there’s an error in gunicorn server

the requirements.txt file :


Please help me out

I also tried different forms of gunicorn and docker run command combinations like

CMD gunicorn -application:app && sudo docker run -e password=$password -p 5000:8000 $reg/web-engine:ve0.0.2

It didnt work
terminal image of container working with development server

I would appreciate a solution involving nothing outside whats mentioned here like nginx, supervisor etc
SOmeone please helllppp meeeeee…….?

Source: StackOverflow