Table of contents
Note
Swarm mode is an advanced feature for managing a cluster of Docker daemons.
See AlsoDocker Swarm vs. Kubernetes - SemaphoreDocker Swarm Vs. Kubernetes: Which One To Choose In 2024 ? - ThinkSys Inc.Run Docker Engine in swarm modeInitializing Docker SwarmUse Swarm mode if you intend to use Swarm as a production runtime environment.
If you're not planning on deploying with Swarm, useDocker Compose instead.If you're developing for a Kubernetes deployment, consider using theintegrated Kubernetes feature in Docker Desktop.
Current versions of Docker include Swarm mode for natively managing a clusterof Docker Engines called a swarm. Use the Docker CLI to create a swarm, deployapplication services to a swarm, and manage swarm behavior.
Docker Swarm mode is built into the Docker Engine. Do not confuse Docker Swarm modewithDocker Classic Swarmwhich is no longer actively developed.
Cluster management integrated with Docker Engine
Use the Docker Engine CLI to create a swarm of Docker Engines where you can deploy applicationservices. You don't need additional orchestration software to create or managea swarm.
Decentralized design
Instead of handling differentiation between node roles at deployment time, the Docker Engine handles any specialization at runtime. You can deploy both kinds of nodes, managers and workers, using theDocker Engine. This means you can build an entire swarm from a single diskimage.
Declarative service model
Docker Engine uses a declarative approach tolet you define the desired state of the various services in your applicationstack. For example, you might describe an application comprised of a web frontend service with message queueing services and a database backend.
Scaling
For each service, you can declare the number of tasks you want torun. When you scale up or down, the swarm manager automatically adapts byadding or removing tasks to maintain the desired state.
Desired state reconciliation
The swarm manager node constantly monitorsthe cluster state and reconciles any differences between the actual state and yourexpressed desired state. For example, if you set up a service to run 10replicas of a container, and a worker machine hosting two of those replicascrashes, the manager creates two new replicas to replace the replicas thatcrashed. The swarm manager assigns the new replicas to workers that arerunning and available.
Multi-host networking
You can specify an overlay network for yourservices. The swarm manager automatically assigns addresses to the containerson the overlay network when it initializes or updates the application.
Service discovery
Swarm manager nodes assign each service in the swarm aunique DNS name and load balance running containers. You can query everycontainer running in the swarm through a DNS server embedded in the swarm.
Load balancing
You can expose the ports for services to anexternal load balancer. Internally, the swarm lets you specify how to distributeservice containers between nodes.
Secure by default
Each node in the swarm enforces TLS mutualauthentication and encryption to secure communications between itself and allother nodes. You have the option to use self-signed root certificates orcertificates from a custom root CA.
Rolling updates
At rollout time you can apply service updates to nodesincrementally. The swarm manager lets you control the delay between servicedeployment to different sets of nodes. If anything goes wrong, you canroll back to a previous version of the service.
What's next?
- Learn Swarm modekey concepts.
- Get started with theSwarm mode tutorial.
- Explore Swarm mode CLI commands