0
0
Dockerdevops~30 mins

Scaling services with replicas in Docker - Mini Project: Build & Apply

Choose your learning style9 modes available
Scaling services with replicas
📖 Scenario: You are managing a simple web service using Docker. To handle more visitors, you want to run multiple copies (replicas) of your service.This project will guide you to create a Docker Compose setup and scale the service replicas.
🎯 Goal: Build a Docker Compose file to define a web service and then scale it to run multiple replicas.
📋 What You'll Learn
Create a Docker Compose file with a web service using the nginx image
Add a configuration variable for the number of replicas
Use the docker-compose command to scale the service
Display the running containers to verify scaling
💡 Why This Matters
🌍 Real World
Scaling services with replicas is common when websites or apps get more visitors. Running multiple copies helps handle more users smoothly.
💼 Career
DevOps engineers often use Docker Compose and scaling commands to manage service availability and performance in real projects.
Progress0 / 4 steps
1
Create a Docker Compose file with a web service
Create a file named docker-compose.yml with a service called web that uses the nginx:latest image.
Docker
Need a hint?

Use YAML syntax to define the service under services: with the name web and specify the image nginx:latest.

2
Add a variable for the number of replicas
Add a variable called REPLICAS in a .env file and set it to 3 to define how many replicas you want.
Docker
Need a hint?

Create a file named .env in the same folder as docker-compose.yml and add the line REPLICAS=3.

3
Scale the web service using the replicas variable
Use the command docker-compose up -d --scale web=${REPLICAS} to start the web service with the number of replicas from the REPLICAS variable.
Docker
Need a hint?

Use the --scale option with docker-compose up -d and pass the replicas variable as ${REPLICAS}.

4
Display running containers to verify scaling
Run docker ps --filter name=web to list all running containers with the name web and verify that there are 3 replicas running.
Docker
Need a hint?

Use docker ps --filter name=web to see all containers with web in their name. You should see 3 containers listed.