0Pricing
Docker & DevOps Fundamentals · Lesson

Scaling and Rolling Updates in Swarm

Scale services across the swarm, perform zero-downtime rolling updates, and roll back automatically when an update goes wrong.

Scaling and Rolling Updates in Swarm is a free Docker & DevOps Fundamentals lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Docker & DevOps Fundamentals learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Services Are Scalable

In Swarm a service describes a desired number of identical container replicas. The swarm manager constantly works to keep that many running across nodes.

Scaling a Service

Change the replica count at any time with docker service scale. The scheduler spreads new tasks across available nodes.

docker service scale web=5

Scale at Create Time

You can also set replicas when creating the service with --replicas.

docker service create --name web --replicas 3 -p 80:80 nginx

Checking Replica Status

Use docker service ls for a summary and docker service ps to see each task and which node it runs on.

docker service ps web

What Is a Rolling Update?

A rolling update replaces replicas a few at a time, so the service stays available throughout. Swarm has this built in.

Triggering an Update

Point a service at a new image with docker service update --image. Swarm replaces tasks gradually per your update policy.

docker service update --image nginx:1.27 web

Controlling the Rollout

Tune the rollout with parallelism and delay: how many tasks change at once and how long to wait between batches.

docker service update \
 --update-parallelism 2 \
 --update-delay 10s \
 --image nginx:1.27 web

Update Failure Action

Set --update-failure-action to rollback so a failing update automatically reverts instead of leaving the service broken.

docker service update \
 --update-failure-action rollback \
 --image nginx:1.27 web

Manual Rollback

If an update misbehaves, docker service rollback instantly returns the service to its previous spec.

docker service rollback web

Health Checks Guide Updates

A container HEALTHCHECK lets Swarm know if a new replica is truly ready. Combined with update policy, this prevents shifting traffic to broken tasks.

HEALTHCHECK --interval=10s CMD curl -f http://localhost/ || exit 1

Global vs Replicated

Replicated services run a fixed count; global services run exactly one task per node - ideal for agents like log collectors. Scaling does not apply to global mode.

docker service create --mode global --name agent myagent

Quick Check

How does a rolling update keep the service available?

Recap

You can now operate Swarm services confidently:

  • docker service scale changes replica counts
  • service update --image triggers rolling updates
  • Parallelism, delay, and --update-failure-action rollback control safety
  • service rollback reverts; health checks gate readiness

Together these give zero-downtime deployments on a swarm.

Frequently asked questions

Is the “Scaling and Rolling Updates in Swarm” lesson free?

Yes — the full text of “Scaling and Rolling Updates in Swarm” is free to read here on the web, and the Docker & DevOps Fundamentals course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Docker & DevOps Fundamentals course, upgrade to CoddyKit PRO.

What will I learn in “Scaling and Rolling Updates in Swarm”?

Scale services across the swarm, perform zero-downtime rolling updates, and roll back automatically when an update goes wrong. You practise Docker & DevOps Fundamentals with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Docker & DevOps Fundamentals?

No prior experience is required. Docker & DevOps Fundamentals on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Scaling and Rolling Updates in Swarm” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Docker & DevOps Fundamentals lesson?

Yes. Every Docker & DevOps Fundamentals lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Introduction to Docker Swarm
  2. Setting Up a Swarm Cluster
  3. Deploying Services to Swarm
  4. Scaling and Rolling Updates in Swarm
← Back to Docker & DevOps Fundamentals