Codementor Events

Django, Hot Reload in Docker (VIDEO)

Published Jun 16, 2023
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

โœ… 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

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 YoutTube material:

Django, HOT Reload in DOCKER - Free Starter - Open-Source Seed project generated by AppSeed.


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

Discover and read more posts from Adi Chirilov - Sm0ke
get started
post commentsBe the first to share your opinion
Show more replies