Learn canary deployments using Docker + Traefik!
A deployment strategy that releases new versions to a small subset of users first, then gradually rolls out to everyone after validating there are no issues.
┌─────────────────┐
│ Traefik │
│ (Load Balancer) │
└────────┬────────┘
│
┌──────────┴──────────┐
│ 90% 10% │
▼ ▼
┌─────────────┐ ┌─────────────┐
│ v1.0.0 │ │ v2.0.0 │
│ (STABLE) │ │ (CANARY) │
└─────────────┘ └─────────────┘
canary-demo/
├── docker-compose.yml # Service definitions
├── traefik-dynamic.yml # Traefik routing config (weights here!)
├── Dockerfile # Container build config
├── server.py # Python web server
├── templates/
│ └── index.html # HTML template
├── test-canary.sh # Test script
└── README.md
docker compose up -d --buildOpen in your browser:
- App: http://localhost (refresh multiple times!)
- Traefik Dashboard: http://localhost:8080
chmod +x test-canary.sh
./test-canary.shYou should see approximately 90:10 distribution.
Edit traefik-dynamic.yml weights:
services:
app-weighted:
weighted:
services:
- name: app-stable@docker
weight: 50
- name: app-canary@docker
weight: 50Traefik will auto-reload the config (no restart needed). Note: Somehow, it requires restart. If it does not change, please perform "docker compose restart traefik"
Run the test again to see the new distribution!
If issues occur, stop the canary:
docker compose stop app-canaryAll traffic now goes to STABLE.
If everything looks good, set CANARY to 100%:
docker compose down