Skip to content
Advertisement

docker-compose, reload server each time I make changes to code

I am dockerizing my Django app and I have the following docker-compose.yml file:

version: '3'

services:
  # other services as db etc.
  web:
    container_name: web
    build:
      context: .
      dockerfile: Dockerfile.web
    restart: 'always'
    env_file:
      - csgo.env
    ports:
      - '8000:8000'
    volumes:
      - web:/code
    depends_on:
      - db

volumes:
  web:

App logs:

System check identified no issues (0 silenced).
web            | September 15, 2022 - 01:38:47
web            | Django version 4.0.7, using settings 'csgo.settings'
web            | Starting development server at http://0.0.0.0:8000/
web            | Quit the server with CONTROL-C.

I want my container (or the app, idk) to reload whenever I let’s say make changes to my models or functions etc. For now, I add some functionality to my app, edit some html views, but no changes appears and the app logs doesn’t say that it’s reloading. I have to rebuild and up my compose again to see my changes. How to do live-reload composing up? How to send changes to docker?

Thanks!

Advertisement

Answer

This may not be the exact answer you are looking for, but it will give you some ideas.

You can add another container to monitor your actions based on the different services. For example; add server “watchchanges” to check the service “my-service”. Then add the command, it can be Django “makemigration && migrate” or assets compile or similar thing.

watchchanges:
    <<: *my-service
    command: python ./manage.py makemigrations --env dev
    restart: unless-stopped
Advertisement