codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
🐳

Docker

12 / 60 topics
12Docker Swarm Basics13Swarm Mode31Docker Swarm Advanced47Docker Swarm Advanced Topics
Tutorials/Docker/Docker Swarm Basics
🐳Docker

Docker Swarm Basics

Updated 2026-05-15
10 min read

Docker Swarm Basics

Introduction

In the world of containerization, managing multiple containers across different machines can become complex and cumbersome. This is where Docker Swarm comes in. Docker Swarm is a native clustering and orchestration tool that turns a pool of Docker hosts into a single virtual Docker host. It allows you to manage multi-container applications with high availability and scalability.

Concept

Docker Swarm operates by creating a cluster of Docker nodes, which can be either managers or workers. Managers are responsible for managing the state of the swarm and scheduling tasks on worker nodes. Workers execute the tasks assigned by the managers. This architecture ensures that your application is highly available and can scale seamlessly as needed.

Examples

Initializing a Swarm

To start using Docker Swarm, you first need to initialize a swarm on one of your machines. This machine will act as the manager node.

Terminal
Output
This node joined a swarm as a worker.

Deploying Services

You can deploy services to your swarm using the docker service create command. This command allows you to define how many replicas of a container should run and other configurations.

Terminal
$ docker service create --name my-web-app --replicas 3 nginx
Output
overall progress: 3 out of 3 tasks 
1/3: running   [==================================================>] 
2/3: running   [==================================================>] 
3/3: running   [==================================================>]

Managing Services

You can manage your services using various Docker commands. For example, you can scale a service to run more replicas.

Terminal
$ docker service scale my-web-app=5
Output
my-web-app scaled to 5
overall progress: 5 out of 5 tasks 
1/5: running   [==================================================>] 
2/5: running   [==================================================>] 
3/5: running   [==================================================>]
4/5: running   [==================================================>]
5/5: running   [==================================================>]

Monitoring the Swarm

You can monitor the state of your swarm and its services using the docker info and docker service ls commands.

Terminal
$ docker info
YAML
1Swarm: active
2NodeID: abc123
3Is Manager: true
4ClusterID: def456
5Managers: 1
6Workers: 2
7CPUs: 8
8Memory: 16GB
Terminal
$ docker service ls
Output
ID             NAME          MODE         REPLICAS   IMAGE
abc789         my-web-app    replicated   5/5        nginx:latest

What's Next?

Now that you have a basic understanding of Docker Swarm, the next step is to explore more advanced features such as Swarm Mode. Swarm Mode allows you to manage your swarm in a more sophisticated way, including load balancing, service discovery, and rolling updates.

By mastering Docker Swarm, you'll be able to deploy and manage complex containerized applications with ease, ensuring high availability and scalability.


PreviousVolumes and Bind MountsNext Swarm Mode

Recommended Gear

Volumes and Bind MountsSwarm Mode