简体   繁体   中英

Unable to Connect to Flask App On Docker on windows

I have a flask app (Dash plotly) and I want to run it on Docker. I did the following things on Linux and it ran successfully:

  • The code for running the flask app: app.run_server(debug=True, host='0.0.0.0')
  • expose the port in the Dockerfile: EXPOSE 8050
  • The code for running the app inside the Dockerfile: CMD ["python", "./app.py"]
  • From the terminal I ran: sudo docker build -t app.
  • From the terminal I ran: sudo docker run -p 8050:8050 --mount type=bind,source=/,target=/tmp app

It provided me the url: 0.0.0.0.8050, and it's works fine.

However, when I downloaded Docker Toolbox on windows 10 and Did exactly the same steps it didn't launch the app on the url that was provided.

Anyone know what's the problem?

It's because docker isn't running natively on Windows. It's running on a virtual Linux machine on Windows. So, instead of using the 0.0.0.0 , you have to check the IP of the toolbox by using:

docker-machine ls

And then replace 0.0.0.0 with the that ip

Update:

If you want to use the host network, you can use the host mode by --network host. But please note that port forward will not work.

reference:

https://docs.docker.com/network/network-tutorial-host/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM