This error occurs when trying to use Docker Swarm features (like overlay networks or swarm commands) on a node that hasn't been initialized as a swarm manager. The fix is to either initialize a swarm, join an existing one, or switch to a non-swarm network driver like bridge.
The "This node is not a swarm manager" error appears when you attempt to use Docker Swarm-specific functionality on a Docker host that isn't part of a swarm cluster. Docker Swarm is Docker's native clustering and orchestration solution, and certain features require swarm mode to be enabled. The most common trigger for this error is attempting to create an overlay network. Overlay networks are designed to connect containers across multiple Docker hosts in a swarm, and they fundamentally depend on the swarm's distributed key-value store to function. Without an active swarm, Docker cannot create or manage overlay networks. This error also appears when running swarm management commands (like `docker node ls`, `docker service create`, or `docker stack deploy`) on a node that isn't a swarm manager. Worker nodes in a swarm can run containers but cannot execute management commands - only manager nodes have that capability. In many cases, developers encounter this error unexpectedly because they specified `driver: overlay` in a docker-compose.yml file without realizing it requires swarm mode, or they're following tutorials written for swarm deployments while running standalone Docker.
First, verify whether your Docker host is part of a swarm and what role it has:
docker info | grep -i swarmIf the output shows Swarm: inactive, the node is not in any swarm. If it shows Swarm: active with Is Manager: false, you're on a worker node.
You can also check with:
docker info --format '{{.Swarm.LocalNodeState}}'This returns inactive, pending, active, or locked.
If you need overlay networks or other swarm features, initialize swarm mode:
docker swarm initOn a machine with multiple network interfaces, specify which IP to advertise:
docker swarm init --advertise-addr <your-ip-address>After initialization, you can create overlay networks:
docker network create -d overlay --attachable my-overlay-networkThe --attachable flag allows standalone containers (not just swarm services) to connect to the overlay network.
If you don't actually need multi-host networking, the simplest fix is to use the bridge driver instead of overlay. Bridge networks work without swarm mode.
In your docker-compose.yml, either remove the driver specification entirely (Docker Compose defaults to bridge):
networks:
my_network:
# No driver specified - defaults to bridgeOr explicitly specify bridge:
networks:
my_network:
driver: bridgeThen recreate the network:
docker-compose down
docker-compose up -dIf you're working with an existing swarm but running commands on the wrong node, you need to SSH into a manager node.
First, identify manager nodes from any node in the swarm:
docker node lsThis command only works from a manager node. If you're on a worker, check your infrastructure documentation or cloud console to find manager IPs.
You can also promote a worker to a manager from an existing manager:
docker node promote <node-name>To demote back to worker:
docker node demote <node-name>If the swarm state is corrupted or you need to start fresh, leave and reinitialize:
# Leave the current swarm (use --force if it's the last manager)
docker swarm leave --force
# Reinitialize
docker swarm initWarning: Using --force on a manager will destroy the swarm if it's the only manager. All services, configs, and secrets will be lost.
If you need to rejoin an existing swarm, get a join token from a manager:
# On a manager node, get token for joining as worker
docker swarm join-token worker
# Or to join as a manager
docker swarm join-token managerThen run the provided join command on the node you want to add.
Understanding overlay vs bridge networks: The overlay driver creates a distributed network spanning multiple Docker hosts, using VXLAN encapsulation. It requires a key-value store to track network state across hosts - in modern Docker, this is provided by swarm's built-in Raft consensus. The bridge driver creates an isolated network on a single host using Linux bridge technology and doesn't require swarm.
Single-node swarm for overlay networks: Even on a single machine, you can initialize a swarm just to use overlay networks. This is useful for testing swarm-based deployments locally:
docker swarm initThere's minimal overhead for a single-node swarm, and you can always leave it later with docker swarm leave --force.
Required ports for multi-node swarms: If you're setting up a multi-node swarm, ensure these ports are open between nodes:
- TCP port 2377: Cluster management communications
- TCP/UDP port 7946: Inter-node communication
- UDP port 4789: Overlay network traffic (VXLAN)
# Example firewall rules (ufw)
sudo ufw allow 2377/tcp
sudo ufw allow 7946/tcp
sudo ufw allow 7946/udp
sudo ufw allow 4789/udpAttachable overlay networks: By default, overlay networks only accept swarm service containers. To allow standalone containers to connect, create the network with --attachable:
docker network create -d overlay --attachable my-networkSwarm certificates expiration: Swarm uses TLS certificates that expire (default: 90 days but auto-rotated). If certificate rotation fails, nodes may be kicked from the swarm. Check certificate status with:
docker swarm ca --rotateDocker Compose and swarm mode: Docker Compose v3+ files can deploy to swarm using docker stack deploy, but docker-compose up runs standalone containers. If your compose file has deploy: keys, it's designed for swarm. For local development without swarm, use Compose v2 syntax or remove swarm-specific configuration.
dockerfile parse error line 5: unknown instruction: RRUN
How to fix 'unknown instruction' Dockerfile parse error in Docker
Error response from daemon: manifest for nginx:nonexistent not found: manifest unknown: manifest unknown
How to fix 'manifest for image:tag not found' in Docker
Error response from daemon: invalid reference format: repository name must be lowercase
How to fix 'repository name must be lowercase' in Docker
Error response from daemon: No such image
How to fix 'No such image' in Docker
Error response from daemon: Container is not running
How to fix 'Container is not running' when using docker exec