I have a Flask app that runs without errors if I run python app.py
locally. It says Running on http://127.0.0.1:5000
, and if I just go to http://127.0.0.1:5000
, everything works like it’s supposed to. The last line of app.py
is app.run(debug=True)
.
Now I’m trying to run this app using Docker. In my Dockerfile, one of the lines is EXPOSE 8501
.
I then build the image with docker build -t testimage .
Finally I execute docker run -it --expose=8501 -p 8501:8501 testimage
, and again it says Running on http://127.0.0.1:5000
.
My questions is :what do I have to enter in my browser to access the app that is running inside the Docker container?
2
Answers
You’re exposing port 8501, but still run the flask app on port 5000. You can should either start the app on exposed port (you can do that using
port
argument toapp.run
) or expose a different port when running docker, matching the one app runs on.let’s this is your flask server code
so flask app is running at port
5000
now this is docker file
now suppose you run
docker run -it -p 5002:5000 image_name
mapping port 5002 of the host(your machine) to port 5000 of docker. so on browser , openhttp://127.0.0.1:5002/
for more info, you can refer my CICD repo