- Регистрация
- 9 Май 2015
- Сообщения
- 1,480
- Баллы
- 155

In previous episodes, we explored Docker Compose for managing multi-container applications. Now, it’s time to move into container orchestration — managing multiple containers across different machines. One of the first orchestration tools introduced by Docker itself is Docker Swarm.

- Docker Swarm is Docker’s native clustering and orchestration tool.
- It allows you to create a cluster of Docker nodes and deploy services across them.
- Provides high availability, scalability, and load balancing.
Think of it as a way to run containers not just on one machine but across many machines working together.

- Node → A machine participating in the swarm (can be physical or virtual).
- Manager Node: Handles cluster management, scheduling, and orchestration.
- Worker Node: Executes the tasks given by the manager.
Service → Defines how containers (called tasks) should run in the swarm.
Task → A running container assigned to a node.
Overlay Network → Enables communication between containers running on different machines.

- Initialize Swarm Mode on the first machine (manager):
docker swarm init --advertise-addr <MANAGER-IP>
- Join Worker Nodes (command is shown after swarm init):
docker swarm join --token <WORKER-TOKEN> <MANAGER-IP>:2377
- Verify Nodes in the Swarm:
docker node ls

Example: Running an nginx service with 3 replicas
docker service create --name my-nginx --replicas 3 -p 8080:80 nginx
Check running services:
docker service ls
docker service ps my-nginx

docker service scale my-nginx=5
This will automatically balance containers across the nodes.

- Easy setup and integration with Docker CLI.
- Provides load balancing out of the box.
- Ensures high availability — if a container fails, Swarm replaces it.
- Secure by default (TLS encrypted communication).

- Small to medium production clusters.
- When you need simpler orchestration than Kubernetes.
- For teams already invested in Docker and looking for an easy scaling solution.


Источник: