25 Jun 2016

Docker swarm mode using Docker 1.12-rc2

I recently returned from Dockercon 2016 in Seattle. The announcements of new features and improvements were many, but one in particular has me very excited. With the release of Docker 1.12-rc2 they introduced Swarm mode! This allows for native orchestration and service discovery without the need of any third party tools.

Tools

You need a few tools installed to follow along with this example.


Create a few boxes for our cluster

Here we are just using docker machine to create 3 virtualbox that will house our swarm.

  • docker-machine create -d virtualbox swarm-manager
  • docker-machine create -d virtualbox swarm1
  • docker-machine create -d virtualbox swarm2


Create the swarm cluster

Here we create a manager which will be able to schedule container to run on the swarm as well as a couple of nodes to participate in the swarm connected to the manager.

The following will setup a swarm cluster on the 3 boxes previously created.

  • eval $(docker-machine env swarm-manager)
  • docker swarm init –listen-addr $(docker-machine ip swarm-manager):2377

  • eval $(docker-machine env swarm1)
  • docker swarm join $(docker-machine ip swarm-manager):2377

  • eval $(docker-machine env swarm2)
  • docker swarm join $(docker-machine ip swarm-manager):2377


Create a service in the Swarm

Here we will just spin up the default nginx container.

  • eval $(docker-machine env swarm-manager)
  • docker node ls
  • docker service create –name nginx -p 80:80 nginx
  • docker service ls


Scaling a service in the swarm

Let’s try to scale our nginx container to 5 spread across the swarm.

  • docker service tasks nginx
  • docker service scale nginx=5
  • docker service tasks nginx

    This is a lot of info. We created 3 virtual machines. Created a swarm. Spun up a nginx container somewhere on the swarm. Finally we scaled the nginx service to 5 containers. There is so much more you can do with the new swarm mode and this is just the tip of the iceberg. I will try to post more on docker as I become more familiar with the new features.

*Disclaimer: since this was introduced in a release candidate the final commands and API could change before being fully released.


Tags:
Stats:
0 comments



© 2017 Jonathan's Site

The opinions expressed here represent my own and not those of my employer or any other groups I am associated with.