In this guide we are going to show you how you can create a swarm.
Make sure the Docker Engine daemon is already started on the host machines.
Start a terminal and ssh into the machine where you would like to run your manager node. This guide uses a machine called manager1.
if you are using Docker machine, you may connect to it from SSH with the following command:
docker-machine ssh manager1
Now execute the following command in order to create a new swarm:
docker swarm init --advertise-addr <MANAGER-IP>
Reminder: In case you are using Docker for Mac or Docker for Windows to test single-node swarm. Just execute docker swarm init without arguments.
It’s not required to specify –advertise-addr in this situation.
In this guide, the following command will create a swarm on the manager1
docker swarm init --advertise-addr 192.168.99.100 Swarm initialized: current node (dxn1zf6l61qsb1josjja83ngz) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join \ --token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \ 192.168.99.100:2377
To add a manager to this swarm, run ‘docker swarm join-token manager’ and follow the instructions.
The flag –advertise-adder configures the manager node to establish its address as 192.168.99.100.
On other nodes, the swarm will have to be able to access the manager at the IP address.
The output contains the commands to get new nodes in the swarm. Nodes should join as managers or workers, relying on the value for the –token flag.
Execute the command docker info in order to see the current state of the swarm.
docker info Containers: 2 Running: 0 Paused: 0 Stopped: 2 ...snip... Swarm: active NodeID: dxn1zf6l61qsb1josjja83ngz Is Manager: true Managers: 1 Nodes: 1 ...snip...
Execute the docker node ls command in order to see information about nodes:
docker node ls ID ID HOSTNAME STATUS AVAILABILITY MANAGER STATUSdxn1zf6l61qsb1josjja83ngz * manager1 Ready Active Leader
What the * means next to the node ID is that you are currently connected on this node. Docker Engine swarm mode automatically calls the node for the machine host name.