0
0
Dockerdevops~10 mins

Blue-green deployment with containers in Docker - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Blue-green deployment with containers
Start with Blue environment live
Deploy new version to Green environment
Test Green environment
Switch traffic
Green becomes live
Blue becomes idle, ready for next update
This flow shows how traffic switches between two container environments (Blue and Green) to deploy updates safely.
Execution Sample
Docker
docker run -d --name blue_app myapp:v1
# Blue is live

docker run -d --name green_app myapp:v2
# Green deployed

docker stop blue_app
# Stop Blue

docker network connect proxy green_app
# Switch traffic to Green
This sequence deploys version 1 on Blue, then version 2 on Green, then switches traffic by stopping Blue and connecting Green to the proxy.
Process Table
StepActionBlue container stateGreen container stateTraffic routingResult
1Run Blue container with v1Running v1Not runningTraffic to BlueBlue app live serving users
2Run Green container with v2Running v1Running v2Traffic to BlueGreen ready but no traffic
3Test Green containerRunning v1Running v2Traffic to BlueGreen verified healthy
4Stop Blue containerStoppedRunning v2Traffic to Blue (stopped)Blue stopped, no traffic served
5Connect Green to proxyStoppedRunning v2Traffic to GreenGreen app live serving users
6Blue idle for next updateStoppedRunning v2Traffic to GreenDeployment complete, ready for next cycle
💡 Blue stopped and traffic switched to Green, deployment finished successfully
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4After Step 5Final
Blue containerNot runningRunning v1Running v1Running v1StoppedStoppedStopped
Green containerNot runningNot runningRunning v2Running v2Running v2Running v2Running v2
Traffic routingNoneTo BlueTo BlueTo BlueTo Blue (stopped)To GreenTo Green
Key Moments - 3 Insights
Why do we keep the Green container running but not serving traffic initially?
Green runs with the new version to allow testing without affecting live users. This is shown in step 2 and 3 where Green is running but traffic is still to Blue.
What happens if the Green environment fails testing?
Traffic stays on Blue, and Green can be fixed or rolled back. This is implied in the decision after step 3 where failure leads to no traffic switch.
Why do we stop the Blue container before switching traffic to Green?
Stopping Blue ensures no conflicting traffic or resource usage. Step 4 shows Blue stopped before traffic is switched in step 5.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the state of the Blue container at step 3?
ANot running
BStopped
CRunning v1
DRunning v2
💡 Hint
Check the 'Blue container state' column at step 3 in the execution table.
At which step does traffic switch from Blue to Green?
AStep 5
BStep 3
CStep 4
DStep 6
💡 Hint
Look at the 'Traffic routing' column to see when traffic moves to Green.
If we did not stop Blue before switching traffic, what would the execution table show at step 5?
ABlue stopped, traffic to Green
BBlue running, traffic to Blue and Green simultaneously
CBlue running, traffic to Green only
DBlue stopped, traffic to Blue
💡 Hint
Think about container states and traffic routing if Blue remains running at step 5.
Concept Snapshot
Blue-green deployment uses two container sets: Blue (live) and Green (new).
Deploy new version to Green while Blue serves users.
Test Green, then switch traffic to Green.
Stop Blue to avoid conflicts.
Green becomes live; Blue idle for next update.
This ensures zero downtime and easy rollback.
Full Transcript
Blue-green deployment with containers means running two versions of an app in parallel. First, the Blue environment runs the current live version. Then, the new version is deployed to the Green environment without affecting users. After testing Green to confirm it works well, traffic is switched from Blue to Green by stopping Blue and routing users to Green. This switch happens smoothly to avoid downtime. Blue then stays idle, ready for the next update cycle. This method helps keep apps running without interruption and allows quick rollback if needed.