0
0
Dockerdevops~30 mins

Canary deployment pattern in Docker - Mini Project: Build & Apply

Choose your learning style9 modes available
Canary Deployment Pattern with Docker
📖 Scenario: You work in a team that manages a web application using Docker containers. Your team wants to deploy a new version of the app safely by using the canary deployment pattern. This means you will run the new version alongside the old one, but only send a small portion of traffic to the new version first. This helps catch problems early without affecting all users.
🎯 Goal: Build a simple Docker Compose setup that runs two versions of a web app: the stable version and the canary version. Configure the setup so that 90% of traffic goes to the stable version and 10% goes to the canary version. This simulates a canary deployment.
📋 What You'll Learn
Create a Docker Compose file with two services: web_stable and web_canary
Use the official nginx image for both services
Configure web_stable to listen on port 8080
Configure web_canary to listen on port 8081
Add a simple nginx configuration file for each service that returns a different message
Create a load_balancer service using nginx that routes 90% of traffic to web_stable and 10% to web_canary
Expose the load balancer on port 80
💡 Why This Matters
🌍 Real World
Canary deployments help teams release new software versions safely by exposing only a small portion of users to changes first. This reduces risk and improves reliability.
💼 Career
Understanding canary deployments and Docker Compose is essential for DevOps roles that manage application releases and infrastructure automation.
Progress0 / 4 steps
1
Create Docker Compose services for stable and canary
Create a docker-compose.yml file with two services: web_stable and web_canary. Use the nginx image for both. Map port 8080 on the host to 80 in web_stable and port 8081 on the host to 80 in web_canary.
Docker
Need a hint?

Use ports to map host ports to container ports for each service.

2
Add custom nginx configuration files for stable and canary
Create two nginx configuration files named stable.conf and canary.conf. In stable.conf, configure nginx to return a simple HTML page with the text Stable Version. In canary.conf, configure nginx to return a simple HTML page with the text Canary Version. Then, update the docker-compose.yml to mount these config files into /etc/nginx/conf.d/default.conf for web_stable and web_canary respectively.
Docker
Need a hint?

Use volumes to mount config files as read-only inside the containers.

3
Add load balancer service with traffic split
Add a new service called load_balancer in docker-compose.yml using the nginx image. Mount a custom nginx config file load_balancer.conf into /etc/nginx/nginx.conf. Expose port 80 on the host. The load balancer will route 90% of traffic to web_stable and 10% to web_canary using nginx upstream and split configuration.
Docker
Need a hint?

Use depends_on to ensure the load balancer starts after the web services.

4
Run Docker Compose and verify canary deployment
Run docker-compose up -d to start all services. Then, run curl -s http://localhost multiple times. You should see Stable Version about 90% of the time and Canary Version about 10% of the time, showing the canary deployment is working.
Docker
Need a hint?

Run docker-compose up -d to start containers. Use curl to test the load balancer. You should see mostly "Stable Version" and some "Canary Version" responses.