Bird
Raised Fist0
Dockerdevops~20 mins

Scaling services with replicas in Docker - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Replica Scaling Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Scaling a Docker service to 3 replicas
You run the command docker service scale webapp=3 on a Docker Swarm cluster. What is the expected state of the service webapp after this command?
AThe service <code>webapp</code> will have 3 replicas on the same node only.
BThe service <code>webapp</code> will be removed and recreated with 3 replicas.
CThe service <code>webapp</code> will have exactly 3 running replicas across the swarm nodes.
DThe command will fail because scaling requires a Docker Compose file.
Attempts:
2 left
💡 Hint
Think about how Docker Swarm manages service replicas across nodes.
🧠 Conceptual
intermediate
2:00remaining
Understanding replica distribution in Docker Swarm
In Docker Swarm, when you scale a service to multiple replicas, how does Swarm decide where to place these replicas?
ASwarm places all replicas on the manager node by default.
BSwarm distributes replicas evenly across worker nodes based on resource availability.
CSwarm places replicas only on nodes with the least CPU usage, ignoring memory.
DSwarm randomly places replicas without considering node resources.
Attempts:
2 left
💡 Hint
Think about how a cluster balances workload.
❓ Configuration
advanced
2:00remaining
Docker Compose file for scaling a service
Which Docker Compose snippet correctly defines a service named api with 4 replicas in a Docker Swarm stack?
A
services:
  api:
    image: myapi:latest
    deploy:
      replicas: 4
B
services:
  api:
    image: myapi:latest
    scale: 4
C
services:
  api:
    image: myapi:latest
    deploy:
      scale: 4
D
services:
  api:
    image: myapi:latest
    replicas: 4
Attempts:
2 left
💡 Hint
Look for the correct key under deploy for replicas.
❓ Troubleshoot
advanced
2:00remaining
Troubleshooting failed scaling of a service
You tried to scale a service to 5 replicas using docker service scale, but only 3 replicas are running. What is the most likely cause?
AThe <code>docker service scale</code> command only supports scaling up to 3 replicas.
BThe service image is missing from the Docker Hub registry.
CThe swarm manager node is offline.
DThere are not enough nodes or resources available in the swarm to run 5 replicas.
Attempts:
2 left
💡 Hint
Consider cluster resource limits and node availability.
🔀 Workflow
expert
3:00remaining
Correct sequence to scale a Docker Swarm service
Arrange the steps in the correct order to scale a Docker Swarm service named frontend from 2 to 5 replicas.
A1,2,3,4
B2,1,3,4
C1,3,2,4
D1,2,4,3
Attempts:
2 left
💡 Hint
Think about checking before and after scaling, then confirming service health.

Practice

(1/5)
1. What does scaling a Docker service with replicas do?
easy
A. Runs multiple copies of the service to handle more work
B. Deletes the service completely
C. Changes the service's network settings
D. Updates the Docker engine version

Solution

  1. Step 1: Understand the purpose of replicas

    Replicas are copies of a service running simultaneously to share the workload.
  2. Step 2: Identify the effect of scaling replicas

    Scaling increases or decreases the number of these copies to improve performance and availability.
  3. Final Answer:

    Runs multiple copies of the service to handle more work -> Option A
  4. Quick Check:

    Scaling = multiple copies [OK]
Hint: Scaling means running more copies of your service [OK]
Common Mistakes:
  • Thinking scaling deletes the service
  • Confusing scaling with network changes
  • Assuming scaling updates Docker itself
2. Which is the correct command to scale a Docker service named webapp to 5 replicas?
easy
A. docker service scale webapp -replicas 5
B. docker scale service webapp 5
C. docker service scale webapp --replicas=5
D. docker service scale webapp=5

Solution

  1. Step 1: Recall the correct syntax for scaling

    The correct syntax is docker service scale SERVICE_NAME=NUMBER.
  2. Step 2: Match the syntax with the options

    docker service scale webapp=5 matches the exact syntax: docker service scale webapp=5.
  3. Final Answer:

    docker service scale webapp=5 -> Option D
  4. Quick Check:

    Correct syntax = docker service scale NAME=NUM [OK]
Hint: Use SERVICE_NAME=NUMBER format with docker service scale [OK]
Common Mistakes:
  • Using wrong command order
  • Adding extra flags not needed
  • Using spaces instead of '='
3. Given the command docker service scale api=3, what will be the number of running containers for the api service?
medium
A. 3 containers
B. 1 container
C. 0 containers
D. Depends on the Docker version

Solution

  1. Step 1: Understand the scale command effect

    The command sets the number of replicas to 3, so Docker runs 3 containers for the service.
  2. Step 2: Confirm the number of containers

    Scaling to 3 means exactly 3 containers will be running for api.
  3. Final Answer:

    3 containers -> Option A
  4. Quick Check:

    Scale api=3 means 3 containers [OK]
Hint: Scale number equals running containers count [OK]
Common Mistakes:
  • Assuming only 1 container runs by default
  • Thinking scaling depends on Docker version
  • Confusing replicas with CPU cores
4. You run docker service scale backend=two but get an error. What is the problem?
medium
A. The service name cannot be 'backend'
B. The number of replicas must be a numeric value
C. The command should be run as root user
D. Docker service scale does not support scaling

Solution

  1. Step 1: Check the scale command syntax

    The replicas count must be a number, not a word.
  2. Step 2: Identify the error cause

    Using 'two' instead of '2' causes a syntax error.
  3. Final Answer:

    The number of replicas must be a numeric value -> Option B
  4. Quick Check:

    Replicas must be numeric [OK]
Hint: Use digits, not words, for replica counts [OK]
Common Mistakes:
  • Using words instead of numbers
  • Assuming service name is invalid
  • Thinking root user is required
5. You have a service app running with 2 replicas. You want to update it to 4 replicas but keep the service running without downtime. Which command should you use?
hard
A. docker service scale app 4
B. docker container run app --replicas 4
C. docker service update --replicas 4 app
D. docker service restart app --replicas 4

Solution

  1. Step 1: Understand how to update replicas without downtime

    Using docker service update --replicas 4 app changes replicas smoothly.
  2. Step 2: Compare options for scaling

    docker service scale can scale but docker service update is preferred for zero downtime updates.
  3. Step 3: Identify incorrect commands

    docker container run and docker service restart do not scale replicas properly.
  4. Final Answer:

    docker service update --replicas 4 app -> Option C
  5. Quick Check:

    Use service update for zero downtime scaling [OK]
Hint: Use 'docker service update --replicas' to avoid downtime [OK]
Common Mistakes:
  • Using docker service scale causing brief downtime
  • Trying to run containers manually
  • Restarting service instead of updating replicas
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard