Contents

How to create a swarm on Docker.

28 Nov 2017 0 82  0
How to create a swarm on Docker.
How to create a swarm on Docker.

 

In this tutorial we will teach you how to create a swarm.

Make sure the Docker Engine daemon is already started on the host machines.

Initiate a New Session

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 command shown below.

docker-machine ssh manager1

Now execute the following command in order to create a new swarm.

docker swarm init --advertise-addr <MANAGER-IP>

Reminder: If you are using Docker for Mac or Docker for Windows to test single-node swarm. Just execute ‘docker swarm init’ without arguments.

It is not required to specify ‘–advertise-addr’ in this situation.

Creating a Swarm

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 command below.

 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 ‘*’ next to the node ID means is that you are currently connected on this node. Docker Engine swarm mode automatically calls the node for the machine host name.

0 Comments
Add a comment

Leave a Reply