Overview
The Wagtail Bakery Demo includes a complete Docker setup with a multi-stage Dockerfile and docker-compose configuration for easy deployment in containerized environments.Prerequisites
Before deploying with Docker, ensure you have:- Docker Engine 20.10 or higher
- Docker Compose 2.0 or higher
- At least 2GB of available RAM
- 10GB of available disk space
Docker Architecture
The docker-compose setup includes three services:Dockerfile Overview
The production Dockerfile is optimized for size and security:Runtime Dependencies
Installs essential system packages:
libpq5- PostgreSQL client librarylibjpeg62-turbo- JPEG image processinglibpcre2-posix3- Regular expressionspostgresql-client- Database utilitiesshared-mime-info- MIME type detection
Python Dependencies
Creates a virtual environment and installs Python packages:Build dependencies are removed after installation to reduce image size.
Quick Start with docker-compose
Basic Setup
Clone the repository and start the services:http://localhost:8000.
docker-compose Configuration
The defaultdocker-compose.yml configuration:
Production Docker Deployment
Production docker-compose Configuration
Create adocker-compose.prod.yml file for production:
Deploy to Production
Docker Entrypoint
Thedocker-entrypoint.sh script handles startup tasks:
- Waits for PostgreSQL to be available before starting
- Runs migrations automatically when starting uWSGI
- Loads initial data if
DJANGO_LOAD_INITIAL_DATA=on - Executes the command passed to the container
uWSGI Configuration
The application uses uWSGI with the following configuration atetc/uwsgi.ini:
- Workers: 2 worker processes for handling requests
- Threads: 4 threads per worker (8 total concurrent requests)
- Static Files: Media files served at
/media/path - Port: Configurable via
PORTenvironment variable (default: 8000) - Lazy Apps: Apps loaded after workers fork for better memory efficiency
Build Arguments
Wagtail Nightly Build
Test against Wagtail’s nightly builds:NIGHTLY=1, the build process:
- Fetches the latest nightly release URL from
https://releases.wagtail.org/nightly/latest.json - Replaces the Wagtail version in
requirements/base.txt - Installs the nightly build instead of the stable version
Docker Best Practices
Image Size Optimization
Image Size Optimization
The Dockerfile follows best practices for minimal image size:
- Uses
python:3.12-slimbase image - Removes build dependencies after installation
- Uses multi-stage build pattern
- No cache for pip installations
- Cleans up apt lists
Security Considerations
Security Considerations
Security features in the Dockerfile:
- Non-root user for media directories (1000:2000)
- Minimal system packages installed
- No debug tools in production image
- Environment variables for sensitive data
- Volume for media files (not baked into image)
Volume Management
Volume Management
Important volumes to persist:
Health Checks
Health Checks
Add health checks to your docker-compose.prod.yml:
Common Docker Commands
Development
Production
Troubleshooting
Container won't start
Container won't start
Check the logs for errors:Common issues:
- Database not ready: The entrypoint script should handle this, but ensure PostgreSQL is running
- Port conflicts: Ensure port 8000 is not already in use
- Environment variables: Verify all required variables are set
Database connection errors
Database connection errors
Verify the database service is running:Test the connection:
Static files not loading
Static files not loading
Ensure static files were collected during build:Manually collect if needed:
Permission errors on media uploads
Permission errors on media uploads
Check media directory permissions:Fix permissions if needed:
Next Steps
Production Settings
Configure production environment variables
Heroku Deployment
Alternative deployment on Heroku
Getting Started
Development setup guide
Deployment Overview
Learn about deployment options

