Let's start

First, SSH into a node we would like to be the first manager, install Docker, and run the docker swarm init command on it. The eth0 is the private network interface provided by the cloud provider. Check yours using the ip addr command before proceeding. If you know which interface is the private one, initialize the cluster using the following command:

$ docker swarm init --advertise-addr=eth0

Next, SSH into the other two nodes. Install Docker and join the cluster using the docker swarm join command. Do not forget that we need to use the join token for the manager, not for the worker. The token in the following example is the manager token. Please note that my first manager's IP is 172.31.4.52 during this setup. Replace it with your IP address:

$ docker swarm join --token SWMTKN-1-5rvucdwofoam27qownciovd0sngpm31825r2wbdz1jdneiyfyt-b5bdh4i2jzev4aq4oid1pubi6 172.31.4.52:2377

For these first three nodes, do not forget to label them as managers to help you remember.

Here, please make sure that docker info shows the list of managers, containing all their private IP addresses. We use grep -A3 to see the next three lines after the target:

$ docker info | grep -A3 "Manager Addresses:"
Manager Addresses:
172.31.0.153:2377
172.31.1.223:2377
172.31.4.52:2377

Or, if you are familiar with the jq command, try the following:

$ docker info --format="{{json .Swarm.RemoteManagers}}" | jq -r .[].Addr
172.31.4.52:2377
172.31.1.223:2377
172.31.0.153:2377

The docker info command also accepts --format to let us customize the output. In the previous example, we used the JSON method provided by the template to generate JSON output. Then we used jq to query the IP addresses of all the Swarm managers. The combination of JSON templating and jq will be a great tool to build our own set of Docker-based scripts for operating clusters in the long term.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset