我有一个tensorflow服务于在docker容器内运行的flask应用程序。我在flask_client.py文件中提供了从容器外部访问的信息。
if __name__ == "__main__":
app.run(host= '0.0.0.0')
当我运行此flask_client.py文件时,
python flask_client.py --server=172.17.0.2:9000
Initialization done.
* Running on http://0.0.0.0:5000/ (press CTRL+C to quit)
我的容器IP地址:172.17.0.2及其在端口9000上的运行
我的虚拟机IP地址:192.168.99.100
并且烧瓶正在http://0.0.0.0:5000/
上运行但是当我试图从http://192.168.99.100:5000/进行访问时,它表明了这一点
但我可以从命令提示符
ping 192.168.99.100和172.17.0.2C:\Windows\system32>ping 192.168.99.100
Pinging 192.168.99.100 with 32 bytes of data:
Reply from 192.168.99.100: bytes=32 time=5ms TTL=64
Reply from 192.168.99.100: bytes=32 time=4ms TTL=64
Reply from 192.168.99.100: bytes=32 time=4ms TTL=64
Reply from 192.168.99.100: bytes=32 time=4ms TTL=64
Ping statistics for 192.168.99.100:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 4ms, Maximum = 5ms, Average = 4ms
C:\Windows\system32>ping 172.17.0.2
Pinging 172.17.0.2 with 32 bytes of data:
Reply from 172.17.0.2: bytes=32 time=4ms TTL=63
Reply from 172.17.0.2: bytes=32 time=4ms TTL=63
Reply from 172.17.0.2: bytes=32 time=4ms TTL=63
Reply from 172.17.0.2: bytes=32 time=4ms TTL=63
Ping statistics for 172.17.0.2:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 4ms, Maximum = 4ms, Average = 4ms
当我厌倦在Docker容器内卷曲时,它显示出类似这样的东西
这些是我的docker容器中的端口和地址:
我现在该怎么办?
PS:我的docker ps显示任何端口
答案 0 :(得分:2)
您需要将Flask应用的内部端口5000映射到主机公共端口。例如,我将192.168.99.100:80映射到您的containers-ip端口5000.
因此,如果您使用本地浏览器http://192.168.99.100进行访问,则会看到container:5000
docker run -d -p 80:5000 your_image
有关Docker run的更多信息,请参阅文档。