Trying the new docker 1.12 swarm mode locally using machine

Written on June 21, 2016 by @marcosnils

Getting started

So, Docker 1.12 has been released in DockerCon US 2016 and if you’ve watched the first day keynote session and demos I’m sure you can’t wait to try all the new stuff that has been announced. The following post contains the necessary steps so you can deploy a docker 1.12 swarm mode locally using machine and start using trying all the new features.

Prerequisites

For the following examples to work you need to download the latest Docker 1.12RC2 for your platform and the pre-release of Docker machine 0.8. Users running docker beta for Mac & Windows will need to download docker-machine only and use the appropriate driver (xhyve / hyper-v) as docker should be upgraded automatically.

Creating the swarm

As docker-machine doesn’t have a straightforward version of creating a swarm mode cluster, we’ll just create stand alone engines and then issue the proper commands to create our cluster.

Create two (or more) engine swarm nodes:

docker-machine create -d virtualbox swmaster # This will be the master
docker-machine create -d virtualbox swnode

Once these commands finish, you should be able to see your docker engines using the standard docker-machine ls command. After you verify that your engines are up and running, next step is to configure your swarm mode cluster:

docker $(docker-machine config swmaster) swarm init --listen-addr $(docker-machine ip swmaster):2377
docker $(docker-machine config swnode) swarm join $(docker-machine ip swmaster):2377 --listen-addr $(docker-machine ip swnode):2377

Once your cluster is created you’re good to go and play around with all the new exciting stuff. Remember to point your local docker client to the swarm master using eval $(docker-machine env swmaster) so you can run all the commands locally.

Show me the magic.

Here’s an example taken from the official Swarm documentation which shows some of the features of the new swarm mode.

Create a new service:

docker service create --replicas 1 --name helloworld alpine ping docker.com

Verify your service status:

docker service ls
docker service inspect --pretty helloworld
docker service tasks helloworld

Scale your service:

docker service scale helloworld=5

Check how the scale worked:

docker service tasks helloworld

Once you’re done, you can remove your service: docker service rm helloworld.

You also have some other cool features like Rolling upgrades, Dynamic loadbalancing which I strongly suggest to look out.

Hopefully this guide will help you to setup a local environment so you can try all these cool features. Some other important announcements were made in the conference so I’d recommend to visit the official DockerCon 2016 site for more info.

via GIPHY