Set a Docker Swarm service to five replicas with two dependable commands

Learn to set a Docker Swarm service to five replicas with two dependable CLI commands: docker service update --replicas 5 my-service and docker service scale my-service=5. See why the other options fail and how Swarm keeps the service in the desired state.

Outline you can skim before we dive in

  • Quick reality check: replicas, swarm mode, and why you’ll care about these commands
  • The two ways to set replicas to 5: A and B explained

  • Why the other two options don’t fit

  • How to verify the change and what it means in a real cluster

  • A few practical takeaways that connect to broader DCA topics

  • A light, human note to keep you grounded during long study sessions

Two ways to set replicas to 5: a straightforward look at the command list

Let me explain the core idea first. In Docker Swarm, a service is a running set of containers that you manage as a single unit. When you say you want more or fewer replicas, you’re telling Docker how many identical tasks should be active at once. It’s like having multiple elevators on a building’s shaft—more elevators means shorter lines, but you’ve got to tell the system how many you want.

Now, the question you’re likely to encounter asks you to pick two commands that change the number of replicas in a service to 5. The two correct options are:

  • A. docker service update --replicas 5 my-service

This command updates the service’s configuration, specifically the replicas field, to 5. It’s the direct way to adjust the desired state of the service without changing other settings. Think of it as modifying the service’s blueprint so that, going forward, it runs five copies of the task.

  • B. docker service scale my-service=5

This one is a bit more blunt in phrasing, but it’s equally valid in practice. The scale command is designed to adjust the number of replicas for a service quickly. It sets the desired replica count to five for the specified service, and Docker Swarm takes the necessary actions to reach that state.

If you’re familiar with Docker’s day-to-day workflow, these two commands feel familiar because they both express, in different syntax, the same intent: “There should be five copies running.” The first option updates the service’s specification, while the second goes straight to the scaling action. Both lead to the same final state when the swarm reconciles it.

The other options—why they don’t fit

Two wrong turns, two wrong options, and that’s okay as long as you understand why they don’t apply here:

  • C. docker service set replicas my-service 5

This sounds plausible, but it isn’t a valid Docker command for changing replicas. It’s the kind of phrasing that can creep into a quiz because it feels like it should exist. But in real Docker CLI, you don’t set replicas with a dedicated “set replicas” subcommand. The swarm expects you to either update the service’s spec or use scale.

  • D. docker change replicas my-service 5

Likewise, this one isn’t a real Docker command. It’s a nice memory hook—people often want a single, simple verb for everything—but the CLI doesn’t provide a command by that name for this purpose. It’s a reminder that not every familiar-sounding phrase translates to an actual tool command.

If you keep in mind the distinction between “update the service spec” and “scale the service now,” you’ll spot those two as traps quickly.

Verifying the change: how to confirm five replicas are running

So you’ve run one of the winning commands. How do you know it worked? A few quick checks help you sanity-check the cluster without pulling your hair out:

  • docker service ls

This shows all services and their current state, including the replica count. Look for my-service and check the REPLICAS column to see five.

  • docker service ps my-service

This lists the tasks for the service. You should see five tasks in the Running state (or at least five desired and some in progress if a rolling update is happening). This is the micro-scan you use to confirm the actual workload.

  • docker service inspect --format '{{.Spec.Replicas}}' my-service

A precise pull of the desired state. It should print 5. If you’re debugging, this is the fastest way to confirm the configuration Docker is aiming for.

  • Quick health check

If your app exposes a health endpoint, a quick curl against the service’s published endpoint can confirm end-to-end reachability. It’s not strictly a replica count check, but it helps ensure the additional replicas are actually serving traffic as intended.

A practical note: replicas aren’t magic

Five replicas don’t just appear out of thin air. Depending on your swarm’s current load, node availability, and resource constraints, Docker will gradually bring up the new tasks to meet the desired state. You may see a rolling update behavior, where new replicas start on available nodes while older ones shut down as the new ones come online. It’s a smart way to maintain availability while you resize capacity.

This is where other DCA topics pop up in real life. You’ll hear about rolling updates, placement constraints, and how to handle failures in a distributed system. The more you understand these concepts, the more your instincts will align with what commands like these are doing under the hood.

Bringing it back to the bigger picture: swarm, services, and everyday ops

If you’re building a mental map of Docker concepts for the DCA landscape, here’s a quick thread to tie this topic to other essentials:

  • Swarm mode basics

You manage a cluster of nodes as a swarm, define services, and let Docker handle the orchestration. Replicas are a core piece of the puzzle because they directly affect availability and throughput.

  • Service updates versus immediate scaling

Update --replicas changes the intended design of the service, not just the momentary state. Scale commands are often used for fast, practical adjustments in response to demand. Both are valid, and knowing when to pick each approach is a big confidence booster in real-world scenarios.

  • Desired state versus actual state

The swarm runs a reconciliation loop. Your job as an operator is to declare the desired state accurately, and then let the system converge to that state. If you say five replicas, the system will try to achieve that, even if it means moving tasks around or restarting them.

A few tips that make topics click

  • Practice with a tiny cluster

If you have access to a local Docker environment with swarm enabled, try creating a small service and then change its replica count a few times with both A and B. Observe how the system responds and how quickly the replica count stabilizes.

  • Watch the logs

When you scale, logs can reveal what’s happening behind the scenes. Look for messages about starting or stopping tasks, node availability, or resource constraints. It’s not just noise—it’s the engine telling you how your command played out.

  • Remember the language of the CLI

Even though the surface-level commands look different, they share a common logic: you’re telling Docker what the service should look like, and the system makes it so. That mental model makes new commands easier to pick up.

A final, human moment

If you’ve ever stood in front of a cluster, wondering which button to press to keep everything humming, you’re not alone. DevOps and container management are less about memorizing a long list of commands and more about understanding the choreography. Replicas aren’t just numbers; they’re a statement about reliability, performance, and how you want your applications to behave under pressure. When you see a question like this, take a breath, map the intent, and pick the two options that align with the swarm’s logic.

Putting it all together: quick recap

  • Two correct ways to set replicas to 5:

  • A. docker service update --replicas 5 my-service

  • B. docker service scale my-service=5

  • Two incorrect, stray options:

  • C. docker service set replicas my-service 5

  • D. docker change replicas my-service 5

  • How to verify: docker service ls, docker service ps, and docker service inspect give you the full picture.

  • Real-world tie-ins: rolling updates, health checks, and the broader swarm orchestration picture.

If you walk away with one takeaway, let it be this: in Docker Swarm, you’re always balancing intent with reality. You declare the intent (five replicas), and the system does the heavy lifting to make it real. The more you practice that mindset, the more naturally these commands will feel, whether you’re testing a small service or scaling a critical microservice to meet user demand.

And if you’re curious about the broader landscape, you’ll notice this thread repeats across many topics in Docker—service updates, rollouts, health probes, and even how you structure your stacks for resilience. The better you understand the logic, the more you’ll recognize the patterns behind the commands, not just the syntax itself. That awareness—that connective, practical understanding—will serve you long after you’ve moved past any single quiz question.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy