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 pypi.python.org -r requirements.txt

# Make port 5000 available to the world outside this container
EXPOSE 5000

# Define environment variable
ENV username root

# Run app.py when the container launches
CMD gunicorn --workers 4 --bind 127.0.0.1:5000 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: http://127.0.0.1:5000 (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

FRom

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

TO

CMD python3.7 application.py

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 :

Flask
Flask-SQLAlchemy
mysqlclient
gunicorn
bs4
html5lib

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