Deploying a minimal flask app in docker - server connection issues

后端 未结 6 1298
清酒与你
清酒与你 2020-11-22 00:51

I have an app who\'s only dependency is flask, which runs fine outside docker and binds to the default port 5000. Here is the full source:

from          


        
6条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-22 01:41

    Your Docker container has more than one network interface. For example, my container has the following:

    $ ip addr
    1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
           valid_lft forever preferred_lft forever
    32: eth0@if33:  mtu 1500 qdisc noqueue state UP group default 
        link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0
        inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
           valid_lft forever preferred_lft forever
    

    if you run docker network inspect bridge, you can see that your container is connected to that bridge with the second interface in the above output. This default bridge is also connected to the Docker process on your host.

    Therefore you would have to run the command:

    CMD flask run --host 172.17.0.2
    

    To access your Flask app running in a Docker container from your host machine. Replace 172.17.0.2 with whatever the particular IP address is of your container.

提交回复
热议问题