and if I choose Running on http://127.0.0.1:5000 , I see that my web app runs truely,
but if I choose
Running on http://172.18.0.2:5000
then it takes longer then ever, and get not open.
my docker-compose file is:
version: ‘3’
services:
web:
build: .
ports:
- “5000:5000”
volumes:
- .:/app:/Desktop/pexonhwdockerfilekopie/app.py
The IP address 172.18.0.2 is internal to Docker. You will never reach it. That’s why you are port forwarding to localhost on your computer with:
ports:
- “5000:5000”
Those lines in the docker-compose.yaml file will forward traffic from http://172.18.0.2:5000 in the container to http://127.0.0.1:5000 on the host computer.
When you used:
app.run(host=‘0.0.0.0’)
That told Flask to bind to all adapters. The two adapters in your container were 127.0.0.1 (i.e., localhost) and 172.18.0.2. The beauty of specifying 0.0.0.0 is that you didn’t need to know the actual IP address that gets assigned to the container. If you run the container again, it may get a different IP address but again, you don’t care. You never use that address. You always address it as http://127.0.0.1:5000.
You are correct. I forgot that if you are running Docker on Linux you actually can reach that IP address. If, however, you are running Docker on Mac or Windows, the IP address is the IP of the hidden VM that Mac and Windows use in the background to provide a Linux host which you can’t reach. Thanks for pointing that out.