无法通过打开的端口访问Docker应用 [英] Docker app cannot be accessed through opened ports

查看:194
本文介绍了无法通过打开的端口访问Docker应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在容器内有一个flask应用程序。我使用

  docker run -p 5000:5000 pyprojects_web 

运行此容器pre>

它会答复

  *正在投放Flask应用程序 debateit.py  
*环境:生产
警告:不要在生产环境中使用开发服务器。
改用生产WSGI服务器。
*调试模式:关闭
*在http://127.0.0.1:5000/上运行(按CTRL + C退出)

如果我运行

  docker container ls 

我得到

 容器ID图像命令创建的状态端口名称
2221298e6e2c pyprojects_web flask run 12分钟前向上12分钟0.0.0.0:5000->5000/tcp elated_joliot

如果我访问 http://127.0.0.1:5000我得到了:

 无法访问该网站
网页位于http://127.0.0.1 :5000 /可能暂时关闭,或者已永久移动到新的网址。
ERR_SOCKET_NOT_CONNECTED

http:// localhost:5000 会给出类似的响应。



通常的建议是使用0.0监听容器内的所有连接。 0.0-但我已经这样做了。这是我的应用程序:

 从应用程序导入应用程序


如果__name__ == __main__:
app.run(host = 0.0.0.0)

如果我从我的容器内部卷曲可以很好地工作:

  docker exec -it 2221298e6e2c curl http:// localhost:5000 

HTML响应较长,并且我的服务器日志得到:

  127.0.0.1--[2018年6月4日01:00:16] GET / HTTP / 1.1 200-

鉴于这些结果,并且考虑到我拥有 0.0.0.0主机,还有什么可以尝试的?



谢谢。

解决方案

因此,基于注释,很明显您实际上并没有在<$ c $上运行c> 0.0.0.0 ,这可能是(注意容器的命令),因为您在运行新版本的flask必须将一些args传递给烧瓶运行-$ =

尝试烧瓶运行--host = 0.0 .0.0 作为容器中的命令,我认为这可能会解决您的期望:)



< a href = http://flask.pocoo.org/docs/1.0/quickstart/ rel = nofollow noreferrer>烧瓶文档。


I have a flask app inside of a container. I run this container with

docker run -p 5000:5000 pyprojects_web

It replies

 * Serving Flask app "debateit.py"
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

If I run

docker container ls

I get

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                    NAMES
2221298e6e2c        pyprojects_web      "flask run"         12 minutes ago      Up 12 minutes       0.0.0.0:5000->5000/tcp   elated_joliot

If I access http://127.0.0.1:5000 I get:

This site can’t be reached
The web page at http://127.0.0.1:5000/ might be temporarily down or it may have moved permanently to a new web address.
ERR_SOCKET_NOT_CONNECTED

http://localhost:5000 gives a similar response.

The normal advice is to listen to all connections inside your container with 0.0.0.0 - but I am already doing that. Here is my app:

from app import app


if __name__ == "__main__":
    app.run(host="0.0.0.0")

If I curl from inside of my container it works perfectly:

docker exec -it 2221298e6e2c curl http://localhost:5000

with a long HTML response, and my server logs get:

127.0.0.1 - - [04/Jun/2018 01:00:16] "GET / HTTP/1.1" 200 -

Given these results, and given that I have a "0.0.0.0" host, what is left to try?

Thanks.

解决方案

So based on the comments it's clear you're not actually running on 0.0.0.0 and that's probably (noticing your command for the container) because you're running a newer version of flask where I think you have to pass some args to flask run.

Try flask run --host=0.0.0.0 as the command in your container and I think that will probably work out how you're expecting :)

More info at the Flask Docs.

这篇关于无法通过打开的端口访问Docker应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆