Skip to main content
Guides/Docker Swarm

Docker Swarm Guide

Docker Swarm turns a pool of Docker hosts into a single virtual host. You deploy services (with replicas) and the swarm schedules them across nodes. See official Swarm docs.

Last updated: April 2026

Check if Swarm is active

Swarm is part of Docker Engine. Check whether the current node is in swarm mode.

docker info | grep -i swarm

Initialize a swarm (manager node)

Run on the machine that will be the manager. Only run once per cluster.

docker swarm init

Deploy a stack

Save your compose file (e.g. stack.yml) and deploy. Use pre-built images (no build: in Swarm unless you build on each node).

docker stack deploy -c stack.yml mystack

Useful Swarm commands

docker service ls
docker node ls
docker service scale mystack_web=3
docker stack rm mystack

Sample stack file

Compose file suitable for docker stack deploy. Uses image only (no build).

services:
  web:
    image: nginx:alpine
    deploy:
      replicas: 2
      restart_policy:
        condition: on-failure
    ports:
      - "80:80"

SwarmBot

AI-powered assistant