Docker Community Forums

Share and learn in the Docker community.

Add auto-reload in django app

I did a lot of searching about how add auto-reload if I did any changing to my local app it doesn’t reload some answers say add volumes to your project directory and I did that but doesn’t work as well
docker-compose.yml

version: '3'
 
services:
 db:
   image: postgres
   environment:
     - POSTGRES_DB=vifa
     - POSTGRES_USER=vifa
     - POSTGRES_PASSWORD=vifa
 web:
   build: .
   restart: always
   command: python manage.py runserver 0.0.0.0:8000
   volumes:
     - .:/VFIA
   ports:
     - "8000:8000"
   depends_on:
     - db

Dockerfile

FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /VIFA 
WORKDIR /VIFA 
COPY requirements.txt /VIFA/
RUN pip install -r requirements.txt
COPY . /VIFA/

You don’t need a browser extension to accomplish auto refreshes. Take a look at https://github.com/tjwalch/django-livereload-server.

I posted a more extensive answer about this at https://stackoverflow.com/a/36961244/2950621

It works by using a manage.py command (server) to monitor your .js and other static files. The server sends a signal to the browser via websockets. There is some client-side code injected on every page. The injected code responds to the signal and refresh the browser.

I am talking about if did change code for example models the server it reloads that what I meant