Search code examples
dockerdocker-swarm

Differences in the ways of creating a Docker swarm


I have been reading a lot of articles and documentation for the past 3 days now about the "new" docker swarm recently built within its engine.

Having identified a couple of ways of creating a swarm (whether it's local or on a cloud provider), I can't help my confusion of understanding the differences between those methods and when you'd use one over the other.

Here are the methods to create a swarm that I have identified so far:

Method 1

docker-machine create -d virtualbox swarm-manager
docker-machine create -d virtualbox swarm-worker-1
docker-machine create -d virtualbox swarm-worker-2

manager_ip=$(docker-machine ip swarm-manager)
swarm_join_command="docker swarm join --token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c 192.168.99.100:2377"

docker-machine ssh swarm-manager "docker swarm init --advertise-addr $manager_ip"

docker-machine ssh swarm-worker-1 "${swarm_join_command}"
docker-machine ssh swarm-worker-2 "${swarm_join_command}"

Method 2

docker-machine create -d virtualbox token

token=$(docker-machine ssh token "docker run swarm create" | tail -n 1)

docker-machine create -d virtualbox \
--swarm --swarm-master \
--swarm-discovery token://${token} \
master-node

docker-machine create -d virtualbox \
--swarm --swarm-discovery token://${token} \
node-01

I am excluding consul because it seems that is no longer needed.

  1. What is the difference between those methods?
  2. When should I use one over the other?

Solution

  • Confusingly there are two implementations of Docker Swarm. The first ran as containers, the second was integrated into the docker Engine as part of the v1.12 release.

    So embrace Method 1. The following example creates a HA setup with multiple managers:


    The older Swarm documentation contains the following:

    You are viewing docs for legacy standalone Swarm. These topics describe standalone Docker Swarm. If you use Docker 1.12 or higher, Swarm mode is integrated with Docker Engine. Most users should use integrated Swarm mode — a good place to start is Getting started with swarm mode and Swarm mode CLI commands. Standalone Docker Swarm is not integrated into the Docker Engine API and CLI commands.