DEV Community

Cover image for Django, Hot Reload in Docker (VIDEO)
Sm0ke
Sm0ke

Posted on • Edited on • Originally published at blog.appseed.us

Django, Hot Reload in Docker (VIDEO)

Hello Coders!

The video mentioned in this article presents Django Corporate an open-source starter enhanced with HOT Reload when running in Docker. This is useful for those that prefer to write the code in isolated environments like Docker and see the changes without restarting the instance (source code saved on GitHub). Thanks for reading!

This enhancement was possible based on the following changes made to the Docker scripts:

✅ Define the codebase as a volume in docker-compose.yml

version: "3.8"
services:
  appseed-app:
    container_name: appseed_app
    restart: always   <-- NEW (For HOT reload)
    build: .
    volumes:
      - ./:/app       <-- NEW (For HOT reload)
    networks:
      - db_network
      - web_network
Enter fullscreen mode Exit fullscreen mode

✅ Force Gunicorn reload in entrypoint.sh

#!/bin/bash
set -e

# Function to start Gunicorn with dynamic reload-extra-file options
start_gunicorn() {
    # Generate the reload-extra-file options dynamically
    extra_files=$(find /app/templates -name "*.html" -printf "--reload-extra-file %p ")

    # Start Gunicorn
    echo "Starting Gunicorn..."
    gunicorn --config gunicorn-cfg.py --reload --reload-engine=poll $extra_files core.wsgi
}

# Start Gunicorn
start_gunicorn
Enter fullscreen mode Exit fullscreen mode

The above changes combined will trigger a HOT Reload in Docker if we change the Python code or the template files. The demonstration of this feature can be visualized in this short YouTube material:


Thanks for reading! For more resources, feel free to access:

👉 More ui themes and templates - free & paid products
👉 Admin Dashboards - a huge index with templates and apps

Top comments (0)