Reputation: 491
While I've seen the other questions -- none of the proposed solutions or documentation has helped me thus far. Apologies if this is somewhat redundant.
I'm trying to mount a volume in my docker-compose.yml
file in order to 'hot-reload' my code as I make changes. I'm running a flask app. My file structure looks as follows:
├── 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
My 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
And finally -- the Dockerfile
in the my_test_app
dir:
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"]
Again -- my goal is to edit the Flask code in the my_test_app
directory and have it reload in my container without starting/stopping.
Thanks in advance for any suggestions!
Upvotes: 4
Views: 2204
Reputation: 491
This was actually related to my Gunicorn command, which requires a --reload
flag.
Steps I used to solve the issue:
1) Since I'm using OSX, I confirmed in my Docker preferences that file-sharing was enabled for this dir.
2) I exec'd into the container to check if the files were updating upon code chagnes:
docker exec -it my-container-name sh
3) They were updating as expected, so I checked the gunicorn/flask documentation.
Upvotes: 8