Simple blue/green deployment setup using Docker Compose and Nginx for zero-downtime failover.
- Docker installed
- Docker Compose installed
- Internet connection (to pull images)
- Clone the repository
git clone <your-repo-url>
cd <repo-name>- Set up environment variables
cp .env.example .env
# Edit .env if needed (default values should work)- Run the deployment script
chmod +x deploy.sh
./deploy.shThe script will:
- Pull Docker images from Docker Hub
- Set up Nginx configuration
- Start all services (nginx, blue app, green app)
- Verify it's running
curl http://localhost:8080/version- Main Service (via Nginx):
http://localhost:8080 - Blue App (direct):
http://localhost:8081 - Green App (direct):
http://localhost:8082
GET /version- Returns app version and pool infoGET /healthz- Health check endpointPOST /chaos/start?mode=error- Simulate failure on the appPOST /chaos/stop- Stop simulated failure
- Check current active pool (should be Blue)
curl -i http://localhost:8080/version
# Look for X-App-Pool: blue header- Trigger chaos on Blue
curl -X POST http://localhost:8081/chaos/start?mode=error- Test automatic failover to Green
curl -i http://localhost:8080/version
# Should now show X-App-Pool: green header
# All requests should return 200 OK- Stop chaos
curl -X POST http://localhost:8081/chaos/stopAll configuration is in .env file:
BLUE_IMAGE=<docker-hub-image-for-blue>
GREEN_IMAGE=<docker-hub-image-for-green>
ACTIVE_POOL=blue
RELEASE_ID_BLUE=v1.0.0-blue
RELEASE_ID_GREEN=v1.0.0-greendocker-compose.yml- Service orchestrationnginx.conf.template- Nginx configuration template.env.example- Environment variables templatedeploy.sh- Automated deployment scriptREADME.md- This fileDECISION.md- Implementation decisions (optional)
docker-compose downServices not starting?
- Check Docker is running:
docker ps - Check logs:
docker-compose logs
Can't connect to localhost:8080?
- Verify nginx container is running:
docker-compose ps - Check if port 8080 is already in use:
lsof -i :8080
Failover not working?
- Check nginx logs:
docker-compose logs nginx - Verify both apps are healthy:
curl http://localhost:8081/healthz
Client Request
↓
Nginx (localhost:8080)
├─→ Blue App (localhost:8081) [Primary]
└─→ Green App (localhost:8082) [Backup]
When Blue fails, Nginx automatically retries the request to Green within the same client request.
- Zero downtime failover is automatic
- Health checks run continuously
- Failed requests are retried to backup automatically
- All upstream headers are preserved# deploy_docker