wal*_*cow 3 flask docker docker-compose
虽然我已经看到了其他问题 - 到目前为止,没有提出的解决方案或文档对我有帮助。如果这有点多余,请道歉。
我正在尝试在我的docker-compose.yml文件中安装一个卷,以便在我进行更改时“热重新加载”我的代码。我正在运行一个烧瓶应用程序。我的文件结构如下:
??? celery_queue
? ??? Dockerfile
? ??? requirements.txt
? ??? tasks.py
??? docker-compose.yml
??? my_test_app
? ??? Dockerfile
? ??? app
? ? ??? __init__.py
? ??? my_test_app.py
? ??? requirements.txt
? ??? worker.py
??? run.sh
??? stop.sh
Run Code Online (Sandbox Code Playgroud)
我的docker-compose.yml:
version: "3"
services:
redis:
image: "redis:alpine"
web:
build:
context: ./my_test_app
dockerfile: Dockerfile
restart: always
volumes:
- ./my_test_app:/my_test_app
ports:
- "5000:5000"
depends_on:
- redis
worker:
build:
context: celery_queue
dockerfile: Dockerfile
depends_on:
- redis
monitor:
build:
context: celery_queue
dockerfile: Dockerfile
ports:
- "5555:5555"
entrypoint: flower
command: -A tasks --port=5555 --broker=redis://redis:6379/0
depends_on:
- redis
Run Code Online (Sandbox Code Playgroud)
最后-的Dockerfile在my_test_app目录:
FROM python:3.6-alpine
ENV CELERY_BROKER_URL redis://redis:6379/0
ENV CELERY_RESULT_BACKEND redis://redis:6379/0
ENV C_FORCE_ROOT true
ENV HOST 0.0.0.0
ENV PORT 5000
ENV DEBUG true
ADD . /my_test_app
WORKDIR /my_test_app
# install requirements
RUN pip install --upgrade pip && \
pip install -r requirements.txt
# expose the app port
EXPOSE 5000
RUN pip install gunicorn
# run the app server
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "--workers", "3", "my_test_app:app"]
Run Code Online (Sandbox Code Playgroud)
再次 - 我的目标是编辑my_test_app目录中的 Flask 代码,并在不启动/停止的情况下将其重新加载到我的容器中。
在此先感谢您的任何建议!
这实际上与我的 Gunicorn 命令有关,它需要一个 --reload标志。
我用来解决问题的步骤:
1) 由于我使用的是 OSX,因此我在 Docker 首选项中确认已为此目录启用文件共享。
2) 我 exec'd 进入容器以检查文件是否在代码更改时更新:
docker exec -it my-container-name sh
3) 他们按预期更新,所以我检查了 gunicorn/flask 文档。
| 归档时间: |
|
| 查看次数: |
1228 次 |
| 最近记录: |