在Docker上运行Flask的教程无法覆盖localhost

时间:2018-12-13 21:30:45

标签: docker docker-compose pycharm

下面是来自https://blog.jetbrains.com/pycharm/2017/03/docker-compose-getting-flask-up-and-running/的非常有用的教程

以示例应用为例,运行docker-compose up,一切正常,URL运行为http://0.0.0.0:5000

但是,在按照PyCharm的设置将项目解释器设置为docker-compose之后,我可以运行,但是无法连接到服务器(连接已重置)。

尝试通过Docker(而不是Docker Compose)配置运行应用程序时,得到相同的结果。

PyCharm中是否需要指定端口转发的区域?

docker-compose up --build的结果:

Building web
Step 1/8 : FROM python:3
 ---> 1e80caffd59e
Step 2/8 : EXPOSE 5000
 ---> Using cache
 ---> fde844406ea1
Step 3/8 : RUN mkdir /app
 ---> Using cache
 ---> 4f00b490f3bf
Step 4/8 : WORKDIR /app
 ---> Using cache
 ---> 032085080f06
Step 5/8 : COPY requirements.txt /app/requirements.txt
 ---> Using cache
 ---> 34bd25f608ad
Step 6/8 : RUN pip install -r requirements.txt
 ---> Using cache
 ---> 6162dfe81ac1
Step 7/8 : COPY . /app
 ---> 4af1cdc75437
Step 8/8 : CMD python flask-compose.py
 ---> Running in 9ca4e6f7e8cd
Removing intermediate container 9ca4e6f7e8cd
 ---> 4887b2161461
Successfully built 4887b2161461
Successfully tagged flask-compose_web:latest
Recreating flask-compose_web_1 ... done
Attaching to flask-compose_web_1
web_1  |  * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
web_1  | 172.22.0.1 - - [14/Dec/2018 14:45:32] "GET / HTTP/1.1" 200 -
web_1  | 172.22.0.1 - - [14/Dec/2018 14:45:32] "GET /favicon.ico HTTP/1.1" 404 -

使用docker-compose配置从IDE运行时记录输出:

FLASK_APP = flask-compose.py
FLASK_ENV = development
FLASK_DEBUG = 0
In folder /Users/mathieson/code/flask-compose
/usr/local/bin/docker-compose -f /Users/someone/code/flask-compose/docker-compose.yml -f /Users/someone/code/flask-compose/docker-compose.dev.yml -f /Users/someone/Library/Caches/PyCharm2018.2/tmp/docker-compose.override.102.yml up --exit-code-from web --abort-on-container-exit web
Recreating flask-compose_web_1 ... 
Attaching to flask-compose_web_1
web_1  |  * Serving Flask app "flask-compose"
web_1  |  * Forcing debug mode off
web_1  |  * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

0 个答案:

没有答案