Docker Swarm in Docker 1.12

By | June 26, 2016
Reading Time: 2 minutes

Having set up my virtual laboratory, I thought I’d take Docker Swarm for a test. After having fiddled around a bit with the old (pre Docker 1.12) way of setting up Docker Swarm, I stumbled upon the documentation for Docker Swarm for Docker 1.12 and later.
In version 1.12, which at the time of writing this only exists as a release candidate, Docker Swarm has been incorporated into the Docker Engine and the Docker Swarm image is no longer needed.

In addition, the documentation has also greatly improved! All in all the new Docker Swarm seems, as far as I am concerned, a large improvement.
Since the tutorial is very good, I do not feel the need to write anything in that area. I will however write a few words on setting up the new Docker Swarm in my virtual laboratory. Please read all the instructions before doing anything!

  • Start up the virtual laboratory.
    I’ll start my virtual laboratory in headless mode and then open four terminal windows in which I log in to the different nodes.
  • Start a root shell on each of the nodes.
    sudo su
  • Check which version of the Docker Engine you are running (remember to check all nodes):
    docker version

    If you are on Docker 1.12 or later, ignore the rest of this step.
    If Docker 1.12 has been released when you read this, update¬†Docker on all nodes. You can try this step if you don’t know whether Docker 1.12 has been released.

    apt-get update
    apr-get upgrade docker-engine

    If Docker 1.12 has not yet been released, you need to uninstall the current Docker Engine and install the latest release candidate.

    apt-get remove -y docker-engine
    curl -fsSL https://test.docker.com/ | sh
  • Select a port on which the Docker Swam management API will be exposed.
    To make it simple, I choose the same port as in the Docker Swarm tutorial, that is 2377.
  • Start the Docker Swam manager.
    I start my manager on the laboratory1 node that has the IP 192.168.1.180.

    docker swarm init --listen-addr 192.168.1.180:2377
  • Start Docker Swarm agents on the three other nodes.
    The three other nodes in my case are laboratory2, laboratory3 and laboratory4. The IP addresses of the agent nodes are not important.

    docker swarm join 192.168.1.180:2377
  • Verify that the Swarm is in the desired state.
    On the manager node, laboratory1 in my case, run the following command:

    docker node ls

    The result should look something like this:

    ID                           NAME         MEMBERSHIP  STATUS  AVAILABILITY  MANAGER STATUS
    4mpcjdm7i9s4e06rdomgk6vdb    laboratory4  Accepted    Ready   Active        
    83cp094axhrammkw02yib6i3v    laboratory2  Accepted    Ready   Active        
    9kk7xbpa5mafgzddzddw6a5ss *  laboratory1  Accepted    Ready   Active        Leader
    axl0ka9p6i1j3wgflx51mck30    laboratory3  Accepted    Ready   Active

Nice and simple!

You are now ready to go on to the Docker Swarm tutorial!

Happy coding!

Leave a Reply

Your email address will not be published. Required fields are marked *