0
0
Dockerdevops~10 mins

Service scaling in Docker - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Service scaling
Start with 1 service instance
Check desired scale number
Compare current instances with desired
Add more instances
Update running services
Scaling complete
This flow shows how Docker service scaling adjusts the number of running instances to match the desired count by adding or removing containers.
Execution Sample
Docker
docker service create --name webapp nginx

docker service scale webapp=3

docker service ps webapp
Create a service named 'webapp' with 1 instance, then scale it to 3 instances, and finally list the running instances.
Process Table
StepCommandCurrent InstancesDesired InstancesActionResult
1docker service create --name webapp nginx01 (default)Create service with 1 instanceService 'webapp' created with 1 instance
2docker service ps webapp11List running instances1 instance running
3docker service scale webapp=313Scale up by adding 2 instancesService scaled to 3 instances
4docker service ps webapp33List running instances3 instances running
5docker service scale webapp=232Scale down by removing 1 instanceService scaled to 2 instances
6docker service ps webapp22List running instances2 instances running
7docker service scale webapp=222No change neededScaling skipped, already at desired count
💡 Scaling stops when current instances equal desired instances.
Status Tracker
VariableStartAfter Step 1After Step 3After Step 5Final
Current Instances01322
Desired Instances1 (default)1322
Key Moments - 3 Insights
Why does the service start with 1 instance even if we don't specify a number?
By default, Docker creates a service with 1 instance as shown in step 1 of the execution_table where desired instances is 1.
What happens if we scale to the same number of instances as currently running?
No scaling action is taken, as shown in step 7 where current and desired instances are both 2, so scaling is skipped.
How does Docker decide whether to add or remove instances?
Docker compares current and desired instances (step 3 and 5). If desired is greater, it adds instances; if less, it removes instances.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 3. How many instances are added to scale the service?
A3
B1
C2
D0
💡 Hint
Check the 'Current Instances' and 'Desired Instances' columns at step 3.
At which step does the service scale down?
AStep 2
BStep 5
CStep 4
DStep 7
💡 Hint
Look for where 'Desired Instances' is less than 'Current Instances' in the execution_table.
If you run 'docker service scale webapp=4' after step 5, what will be the new 'Current Instances'?
A4
B3
C2
D5
💡 Hint
Scaling up increases instances to the desired number as shown in step 3.
Concept Snapshot
Service scaling in Docker adjusts the number of running containers.
Use 'docker service scale <service>=<count>' to set desired instances.
Docker adds or removes containers to match the desired count.
Default service creation starts with 1 instance.
Check running instances with 'docker service ps <service>'.
Full Transcript
Service scaling in Docker means changing how many copies of a service run. When you create a service, it starts with one instance by default. You can increase or decrease this number using the 'docker service scale' command. Docker compares the current number of instances with the desired number. If you want more, Docker adds instances. If you want fewer, Docker removes some. You can check how many instances are running with 'docker service ps'. This process helps manage load and availability easily.