Gayatri
Gayatri

Reputation: 2253

Expose a different port for Flask App inside Docker Container

I built a flask app using docker container which works well on port 5000. However in order to expose a different port I have to put in the port in app.py as

if __name__ == '__main__':
    app.run(debug=True,host='0.0.0.0',port=6000)

which works well once I start the docker container.

However, When I just do

if __name__ == '__main__':
    app.run(debug=True,host='0.0.0.0')

and in the Dockerfile say

EXPOSE 6000

and run the flask app on the docker container, it does not run on port 6000 instead runs of port 5000. Why is that so? Is exposing the port number in the dockerfile not enough for the flask app?

Upvotes: 5

Views: 11374

Answers (1)

BOC
BOC

Reputation: 1139

Your flask app has no clue about which port is put in dockerfile. You can leave your application at the default port and tell docker to expose it on the desired port with the -p option:

docker run -i -t -p 6080:5000 ...

see https://docs.docker.com/network/links/#connect-using-network-port-mapping for more details.

Upvotes: 5

Related Questions