This tutorial will show you how to get your first Docker swarm up and running. In my example, I am using two Ubuntu machines, one will be the master and one will be the worker.
Install Docker Community Edition on the machines.
Follow the instructions on the website in order to install docker ce for Ubuntu.
Check Docker is installed by running:
Install Docker machine:
Docker machine will allow us to install a docker engine on our machines and manage them using docker-machine commands. You can find out more about Docker machine on their website.
curl -L https://github.com/docker/machine/releases/download/v0.16.0/docker-machine-`uname -s`-`uname -m` >/tmp/docker-machine && chmod +x /tmp/docker-machine && sudo cp /tmp/docker-machine /usr/local/bin/docker-machine
I have installed docker machine on both of the hosts.
On both servers, we need to change the hosts file via command line. You will need to add two lines to the end of the file. The easiest way to do this is using vim text editor, which will allow you to edit the file in command line. We need to add the ip address of each machine and let it know which is the manager and which is the worker.
If you have additional workers then you can add worker02, worker03 etc.
sudo vim /etc/hosts 10.0.16.5 manager 10.0.16.4 worker01
We now need to run the following from the manager machine:
sudo docker swarm init --advertise-addr 10.0.16.5
We will get a response back, which will be a docker swarm join that we then need to run on the worker machine. It will look something like this (example from dockers own swarm tutorial):
To add a worker to this swarm, run the following command: docker swarm join \ --token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \ 192.168.99.100:2377
Once you have done this your swarm will be up and running. If you run:
you will be able to see the details of your swarm, including how many nodes, managers, containers etc.
Here are some useful links on Docker swarm that I used to get mine up and running:
Next time we will look at getting something up and running in docker swarm mode.