7

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.

Luis Liz
  • 1,939
  • 4
  • 20
  • 31
  • 1
    Hi Luis. We like to use https://github.com/gorakhargosh/watchdog in combination with docker. All you do is add watchdog to your requirements.txt file, and in your docker-compose.yml file add `command: watchmedo auto-restart --recursive --pattern="*.py" --directory="/path/to/your/app" python -- -m server` – Reez0 Oct 26 '20 at 07:16
  • I think this solves my problems. Thanks! Mind putting it as an answer? so I can accept it – Luis Liz Oct 26 '20 at 16:08

1 Answers1

5

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/
Reez0
  • 2,512
  • 2
  • 17
  • 39