top of page

1. What is Docker Swarm?


What is Docker Swarm?


It helps you:

  • Run multiple containers

  • Scale containers

  • Distribute traffic

  • Provide self-healing


    If Docker runs one container,

    Docker Swarm manages many containers together.


  1. Check Docker Installation

Open PowerShell / CMD / Terminal

docker --version

If Docker is installed, you will see version output.


  1. Initialize Docker Swarm

Now convert your machine into a Swarm Manager Node

docker swarm init

What happens internally?

  • Your system becomes Manager Node

  • Docker creates:

    1. Swarm cluster

    2. Internal network

    3. Raft database (stores cluster state)

You will see output like:

Swarm initialized: current node (xxxxx) is now a manager.

4: Check Swarm Nodes

docker node ls

You will see something like:


Your machine is now:

  • Manager

  • Leader

  • Active


5: Create First Service

Now we create a service using Nginx.

What is Service?


In Swarm:

We don’t create containers directly. We create services.

  • Service manages containers automatically.


Run:

docker service create --name myweb -p 8090:80 nginx

Explanation of command:

Part

Meaning

docker service create

Create swarm service

--name myweb

Service name

-p 8090:80

Map port 8090 (host) → 80 (container)

nginx

Image


6: Check Service

docker service ls

You will see:



What is 1/1?

1 desired replica

1 running replica

7: Check Running Container (Task)

docker ps

You will see a container running.

Swarm automatically created it.

Step 8: Open Browser

Now open:

You should see:


That means Swarm service is working successfully


Step 9: Scale the Service

Now let’s scale to 3 containers.

docker service scale myweb=3

Check again:

docker service ls

Now you will see:

myweb   replicated   3/3   nginx

Swarm created 3 containers automatically.

Step 10: See All Containers

docker ps

You will see 3 nginx containers running.


Step 11: How Load Balancing Works

Even if 3 containers are running,You still access:

Swarm automatically:

Distributes traffic

Balances load between containers


You don’t configure load balancer manually.

Swarm has built-in Routing Mesh.


Step 12: Remove Service

Now delete service:

docker service rm myweb

Check:

docker service ls

It will be empty.

All containers are automatically removed.

Step 13: Leave Swarm


If you want to stop swarm:

docker swarm leave --force

Now your machine is normal Docker again.

What You Learned in This Practical

Concept

You Practiced

Swarm Init

Created cluster

Node

Manager Node

Service

Created service

Replica

Scaled containers

Load Balancing

Automatic

Self-Healing

Managed by Swarm

Difference between Kubernetes and Swarm



No

Feature

Docker Swarm

Kubernetes

Explanation

1

Definition

Built-in orchestration tool in Docker

Open-source container orchestration platform by Google

Swarm is part of Docker. Kubernetes is a separate powerful system.

2

Setup

Very simple

More complex

Swarm: docker swarm init and done. Kubernetes: needs cluster setup (minikube, kubeadm, AKS, etc.).

3

Learning Curve

Easy

Medium to Difficult

Swarm is beginner-friendly. Kubernetes needs more understanding of concepts.

4

Architecture

Manager + Worker nodes

Control Plane + Worker nodes

Kubernetes has more internal components like API server, etcd, scheduler.

5

Main Unit

Service

Pod

Swarm manages “services”. Kubernetes runs containers inside “pods”.

6

Scaling

Manual scaling

Manual + Auto scaling

Swarm: docker service scale. Kubernetes: can auto-scale based on CPU (HPA).

7

Load Balancing

Built-in Routing Mesh

Service + kube-proxy + Ingress

Swarm automatically balances traffic. Kubernetes needs service objects.

8

Self-Healing

Yes

Yes (More advanced)

Both restart failed containers. Kubernetes can reschedule pods on different nodes.

9

Rolling Updates

Basic

Advanced

Kubernetes supports zero-downtime updates with better control.

10

Networking

Simple overlay network

Advanced CNI networking

Kubernetes supports complex networking plugins.

11

Storage

Basic volume support

Advanced persistent volumes

Kubernetes handles storage more professionally.

12

Secrets Management

Basic

Strong secret & config management

Kubernetes has ConfigMaps and Secrets.

13

Community Support

Smaller

Very Large

Kubernetes has massive global community.

14

Cloud Support

Limited

Fully supported (AKS, EKS, GKE)

All major clouds support Kubernetes as managed service.

15

Industry Usage

Low (declining)

Very High

Most companies use Kubernetes today.

16

Best For

Small apps, learning

Large production systems

Swarm = simple projects. Kubernetes = enterprise systems.


DOCKER SWARM VS KUBERNETES



When we run one container using Docker, it works fine for small applications. But in real-world projects, we need:


  1. Multiple containers

  2. Load balancing

  3. Auto restart if container fails

  4. Scaling up and down

  5. Zero downtime updates


To manage all this, we use container orchestration tools.


Two popular orchestration tools are:

  1. Docker Swarm

  2. Kubernetes


    What is Docker Swarm?

Docker Swarm is a container orchestration tool that comes built inside Docker.

It allows us to:

  1. Create a cluster of machines

  2. Run multiple containers

  3. Scale containers

  4. Automatically restart failed containers

  5. Distribute traffic between containers


The biggest advantage of Swarm is simplicity.


To start Swarm, we just run:


docker swarm init


That’s it. Our machine becomes a manager node.

Swarm is easy to learn and good for beginners.


  1. What is Kubernetes?

Kubernetes is a powerful container orchestration platform developed by Google.

It is designed to manage large-scale production applications.

Kubernetes can:


  1. Deploy containers across many machines

  2. Automatically scale based on CPU usage

  3. Perform rolling updates with zero downtime

  4. Manage secrets and configuration

  5. Move workloads if a node fails

  6. Integrate with cloud platforms


Kubernetes is more powerful, but also more complex.


  1. Architecture Difference


Docker Swarm Architecture

Swarm has two main components:

  1. Manager Node

  2. Worker Node

Manager:

  1. Controls the cluster

  2. Decides where containers run


  1. Runs containers

Swarm architecture is simple and easy to understand.

Kubernetes Architecture


Kubernetes has more internal components:


Control Plane:

  1. API Server

  2. Scheduler

  3. Controller Manager

  4. etcd database


Worker Nodes:

Run Pods (which contain containers)

Kubernetes architecture is more complex because it gives more control and flexibility.


Basic Working Unit

In Docker Swarm:We create a Service.

Example:docker service create --name myweb nginx

The service manages containers automatically.

In Kubernetes:We create a Pod (inside a Deployment).

Example:kubectl create deployment myweb --image=nginx

A Pod can contain one or more containers.

Important concept:Swarm manages services.Kubernetes manages pods and deployments.

  1. Scaling

In Docker Swarm:

docker service scale myweb=3

This creates 3 containers.

Scaling is manual.

In Kubernetes:

kubectl scale deployment myweb --replicas=3

Additionally, Kubernetes supports auto scaling using HPA (Horizontal Pod Autoscaler).

This means Kubernetes can automatically increase or decrease pods based on CPU or memory usage.

Swarm does not have advanced auto scaling.

  1. Load Balancing

In Docker Swarm:

Swarm has built-in routing mesh.

When you publish a port like:

-p 8090:80

Swarm automatically distributes incoming traffic between all replicas.

You do not need to configure a load balancer manually.

In Kubernetes:

Load balancing works using:

  • Service objects

  • kube-proxy

  • Ingress (for external traffic)

Kubernetes gives more flexible and advanced load balancing, but requires configuration.

  1. Self-Healing

In Docker Swarm:

If a container crashes, Swarm automatically restarts it.

If you say replicas = 3,Swarm always tries to maintain 3 running containers.

In Kubernetes:

If a pod crashes, it restarts.

If an entire node fails, Kubernetes can move pods to another healthy node.

Kubernetes self-healing is more intelligent and advanced.

  1. Rolling Updates

In Docker Swarm:

Swarm supports rolling updates.But configuration options are limited.

In Kubernetes:

Rolling updates are more controlled.You can:

  • Control how many pods update at a time

  • Pause updates

  • Roll back to previous version easily

Kubernetes provides more enterprise-level control.

  1. Networking

Docker Swarm:

Uses simple overlay networking.Easy to configure.

Kubernetes:

Uses CNI plugins.Supports complex networking models.Can integrate with service mesh tools.

For small projects, Swarm networking is enough.For enterprise systems, Kubernetes networking is better.

  1. Storage Management

Docker Swarm:

Supports Docker volumes.Basic persistent storage.

Kubernetes:

Supports Persistent Volumes and Persistent Volume Claims.Works with cloud storage like Azure Disk, AWS EBS.

Kubernetes handles storage in a more structured way.

  1. Cloud Support and Industry Usage

Docker Swarm:

  • Less commonly used today

  • Limited managed cloud services

Kubernetes:

  • Industry standard

  • Supported by:

    • Azure (AKS)

    • AWS (EKS)

    • Google (GKE)

Most companies today prefer Kubernetes for production systems.

  1. When to Use What?

Use Docker Swarm when:

  • You are learning container orchestration

  • The application is small

  • You need quick setup

  • You want simplicity

Use Kubernetes when:

  • Application is large

  • High traffic

  • Enterprise-level system

  • Need auto scaling

  • Need cloud integration

  • Simple Real-World Example

Imagine an e-commerce website.

Small startup:

  • 3 containers

  • Basic load balancing

  • Manual scaling

Swarm is enough.

Large company like Amazon:

  • Thousands of containers

  • Auto scaling based on traffic

  • Zero downtime updates

  • Multi-region deployment

  • Cloud integration

Kubernetes is required.

  1. Final Summary

Docker Swarm is simple, beginner-friendly, and easy to set up.

Kubernetes is powerful, scalable, and industry standard, but more complex.




$50

Product Title

Product Details goes here with the simple product description and more information can be seen by clicking the see more button. Product Details goes here with the simple product description and more information can be seen by clicking the see more button

$50

Product Title

Product Details goes here with the simple product description and more information can be seen by clicking the see more button. Product Details goes here with the simple product description and more information can be seen by clicking the see more button.

$50

Product Title

Product Details goes here with the simple product description and more information can be seen by clicking the see more button. Product Details goes here with the simple product description and more information can be seen by clicking the see more button.

Recommended Products For This Post
 
 
 

Recent Posts

See All
Roll Update and Roll back with Kubernetes

Project: student-feedback-app This is a simple Flask application that: Shows Application Version Shows Environment Mode Runs inside Docker Deployed in Kubernetes Uses Rolling Update Uses ConfigMap Eve

 
 
 
How to Use Blackbox AI for Free in DevOps

DevOps engineers constantly write Dockerfiles, Kubernetes YAMLs, CI/CD pipelines, Terraform scripts, and shell automation . Writing all of this manually takes time and increases the chance of configur

 
 
 

Comments


© 2023 by newittrendzzz.com 

  • Facebook
  • Twitter
  • Instagram
bottom of page