Reputation: 1959
I'm developing some python microservices with grpc and i'm using docker for the cassandra database and the microservices. Is there a way to setup reload on change within docker-compose?
I'm guessing that first I need the code mounted as a volume but I don't see a way to reload on GRPC server like for example flask does.
Upvotes: 8
Views: 2779
Reputation: 2689
We use watchdog[watchmedo]
with our grpc services and Docker.
Install watchdog or add to your requirements.txt
file
python -m pip install watchdog[watchmedo]
Then in your docker-compose.yml
add watchmedo auto-restart --recursive --pattern="*.py" --directory="/usr/src/app/" python -- -m app
to your container where --directory
is the directory to where your app is contained inside the docker container, and python -- -m app
is the file that starts your grpc Server. In this example the file that starts the server is called app.py
:
app:
build:
context: ./app/
dockerfile: ./Dockerfile
target: app
command: watchmedo auto-restart --recursive --pattern="*.py" --directory="/usr/src/app/" python -- -m app
volumes:
- ./app/:/usr/src/app/
Upvotes: 8