虽然我已经看到了其他问题--到目前为止,没有一个建议的解决方案或文档对我有帮助。如果这有点多余的话,很抱歉。
我正在尝试在我的docker-compose.yml
文件中装载一个卷,以便在我进行更改时‘热重新加载’我的代码。我在运行一个flask应用。我的文件结构如下:
├── 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
我的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
最后-- my_test_app
目录中的Dockerfile
:
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"]
同样--我的目标是编辑my_test_app
目录中的Flask代码,并让它在不启动/停止的情况下重新加载到我的容器中。
提前感谢您的任何建议!
发布于 2018-12-18 03:51:14
这实际上与我的Gunicorn命令有关,该命令需要一个--reload
标志。
我用来解决这个问题的步骤:
1)由于我使用的是OSX,我在我的Docker首选项中确认了此目录的文件共享已启用。
2)我执行了容器,以检查文件是否在代码更改时更新:docker exec -it my-container-name sh
3)它们正在按预期进行更新,所以我查看了gunicorn/flask文档。
https://stackoverflow.com/questions/53809651
复制相似问题