Django, Hot Reload in Docker (VIDEO)
The sample mentioned in this article provides a HOT Reload in Docker when the Django code is updated or the templates.
Hello! 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). Thank you!
- 👉 Django Corporate - official
Product Page
- 👉 Django Corporate -
LIVE Demo
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: