Skip to content

Major-root/deploy_docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Blue/Green Deployment with Nginx

Simple blue/green deployment setup using Docker Compose and Nginx for zero-downtime failover.

Prerequisites

  • Docker installed
  • Docker Compose installed
  • Internet connection (to pull images)

Quick Start

  1. Clone the repository
   git clone <your-repo-url>
   cd <repo-name>
  1. Set up environment variables
   cp .env.example .env
   # Edit .env if needed (default values should work)
  1. Run the deployment script
   chmod +x deploy.sh
   ./deploy.sh

The script will:

  • Pull Docker images from Docker Hub
  • Set up Nginx configuration
  • Start all services (nginx, blue app, green app)
  1. Verify it's running
   curl http://localhost:8080/version

Endpoints

  • Main Service (via Nginx): http://localhost:8080
  • Blue App (direct): http://localhost:8081
  • Green App (direct): http://localhost:8082

Available Routes

  • GET /version - Returns app version and pool info
  • GET /healthz - Health check endpoint
  • POST /chaos/start?mode=error - Simulate failure on the app
  • POST /chaos/stop - Stop simulated failure

Testing Failover

  1. Check current active pool (should be Blue)
   curl -i http://localhost:8080/version
   # Look for X-App-Pool: blue header
  1. Trigger chaos on Blue
   curl -X POST http://localhost:8081/chaos/start?mode=error
  1. 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
  1. Stop chaos
   curl -X POST http://localhost:8081/chaos/stop

Configuration

All 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-green

Files in This Repo

  • docker-compose.yml - Service orchestration
  • nginx.conf.template - Nginx configuration template
  • .env.example - Environment variables template
  • deploy.sh - Automated deployment script
  • README.md - This file
  • DECISION.md - Implementation decisions (optional)

Stopping the Services

docker-compose down

Troubleshooting

Services 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

Architecture

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.

Notes

  • Zero downtime failover is automatic
  • Health checks run continuously
  • Failed requests are retried to backup automatically
  • All upstream headers are preserved# deploy_docker

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages