Problem:
From the windows host machine. Port mapping/exposing does not work.
Container app is not reachable.
curl http://localhost:PORT (127.0.0.1 / 0.0.0.0)
-> Could not get any response
curl http://DOCKER-IP:PORT (127.17.0.1 / 127.17.0.2)
-> Could not get any response
curl http://DOCKER-SUBNET-ADDRESS:PORT (10.0.75.0)
-> Could not get any response
Setup:
Windows10 host system + Docker container (with simple helloworld python flask app)
Docker container is running. Inside the docker container the flask app behaves as expected.
Reproduction:
get the hello world repo
git clone https://github.com/shekhargulati/python-flask-docker-hello-world
Build and run docker container
docker build -t simple-flask-app:latest .
docker run -d -p 5000:5000 simple-flask-app --name simple-flask-app
exec into container & check flask is running
docker exec -it simple-flask-app
apt-get install curl
curl http://127.0.0.1:5000
-> See 200 OK + Flask is running
(or some text like this)
Exit docker container
exit
curl on your windows host machine
curl http://127.0.0.1:5000
-> See Could not get any response
(or something like this)
You need to set the app to run on host='0.0.0.0'. That is:
app.run(host='0.0.0.0')
So when you run:
> docker run -d -p 5000:5000 simple-flask-app --name simple-flask-app
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
* Restarting with stat
Then curl http://localhost:5000
works.
Credit goes to: https://codefresh.io/docker-tutorial/hello-whale-getting-started-docker-flask/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With