简体   繁体   English

Docker-在代理上运行Flask Web应用程序

[英]Docker - running a Flask web application on a proxy

I have a small web application the runs on a flask server, which can normally be run on local host, by running app.py. 我有一个小型Web应用程序,它在flask服务器上运行,通常可以通过运行app.py在本地主机上运行。 I would like to run it in a docker container, so I cannot use localhost. 我想在docker容器中运行它,所以我不能使用localhost。 An alternative would be using 0.0.0.0 , which works fine normally, however this does not work when I'm on my work proxy. 另一种选择是使用0.0.0.0 ,它通常可以正常工作,但是当我在工作代理上时,这将不起作用。

How could I get past this issue? 我如何解决这个问题?

app.py app.py

from flask import Flask, render_template
app = Flask(__name__)


@app.route("/")
def main():
    return render_template('index.html')

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

Dockerfile Dockerfile

FROM python:2.7.13

ADD . /code
WORKDIR /code

RUN pip install Flask --proxy=[proxy]

CMD ["python", "app.py"]

You don't need to use a proxy inside the container. 您无需在容器内使用代理。 Whatever is needed will be external to the container/image. 所需的一切将在容器/图像的外部。 Whether your run in corporate environment or home. 无论您是在公司环境中运行还是在家中运行。

When you use docker run -p 5000:5000 <yourimage> . 当您使用docker run -p 5000:5000 <yourimage> It maps the port 5000 from inside the container to all interfaces on your machine. 它将端口5000从容器内部映射到计算机上的所有接口。

Now if you machine is reachable from other machines in network, then they need to use http://<yourreachablemachineip>:5000 . 现在,如果您的计算机可以从网络中的其他计算机访问,则它们需要使用http://<yourreachablemachineip>:5000 Also if for some reason a proxy is needed then you will need to apply that proxy to docker daemon and not to inside the docker container. 另外,如果由于某种原因需要代理,那么您将需要将该代理应用于docker守护进程,而不是应用于docker容器内部。 See below thread for more details on the same 参见下面的主题以获取更多详细信息

lookup registry-1.docker.io: no such host 查找注册表-1.docker.io:无此类主机

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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