The host cannot access the flask service in docker

Scenes

Use the docker container to deploy a small web application in the Linux system. The project directory is as follows:

The Dockerfile content is:

The content of start.sh is:

There is no problem with docker build creating a mirror↓

Then run the image, run a container, name the container df2, and run it in the background in interactive mode, and map the container port and host port to 5000, as follows:

Check the container information and enter the container, and visit the URL of the web application: 127.0.0.1:5000. prefect! Perfect! !

Do you think this is the end? Naive -_-
can run successfully inside the container, but what about mapping to the host?
Accessing on the host becomes like this bear. . . . . . , and the browser cannot access it. . . . . .

After half a century of exploration and colleagues' advice, I finally found the problem: because I am using the flask project, the default host used for project startup is 127.0.0.1, and the port port is 5000, while our docker port is mapped by default to the host It is 0.0.0.0, so you need to change the flask listening address to 0.0.0.0, like this:

Then delete the container, delete the image, change the address, rebuild the build image, and run the container... Finally, the problem is solved↓

Thank you for your guidance, the original link: docker container deployment web application host cannot be accessed-KuangStudy-article 

Guess you like

Origin blog.csdn.net/m0_52948781/article/details/127528667