Contents

Docker Swarm Introduction

Website Visitors:
Contents

Docker Swarm

Docker Swarm is a native Docker orchestration tool that allows you to deploy and manage multiple Docker containers as a single unit. In this article, we’ll cover the basic setup of Docker Swarm, including creating a swarm, adding nodes, and deploying a service.

Prerequisites

  • Docker installed on multiple machines (nodes)
  • Docker version 1.12 or later
  • All nodes must be able to communicate with each other

Step 1: Create a Swarm

On one of the nodes, run the following command to create a new swarm:

1
docker swarm init

This command will create a new swarm and make the current node the manager node.

Step 2: Add Nodes to the Swarm

On each additional node, run the following command to join the swarm:

1
docker swarm join <manager-node-ip>:2377

Replace <manager-node-ip> with the IP address of the manager node.

Step 3: Verify the Swarm

Run the following command on the manager node to verify the swarm:

1
docker node ls

This command will list all nodes in the swarm, including their status and roles.

Step 4: Deploy a Service

Create a new service using the following command:

1
docker service create --name myservice --replicas 3 -p 8080:80 nginx

This command will create a new service named “myservice” with 3 replicas, exposing port 8080 on the host and mapping it to port 80 in the container.

Step 5: Verify the Service

Run the following command to verify the service:

1
docker service ls

This command will list all services in the swarm, including their status and number of replicas.

Basic Swarm Architecture

Here’s a high-level overview of the basic swarm architecture:

  • Manager Node: The node that creates and manages the swarm.
  • Worker Nodes: The nodes that join the swarm and run services.
  • Services: The applications or containers that are deployed and managed by the swarm.

That’s it! You now have a basic Docker Swarm setup with a single service running on multiple nodes. From here, you can explore more advanced features and configurations to suit your needs.

Your inbox needs more DevOps articles.

Subscribe to get our latest content by email.