Docker Swarm is native clustering for Docker. It turns a pool of Docker hosts into a single, virtual host.
Swarm serves the standard Docker API, so any tool which already communicates with a Docker daemon can use Swarm to transparently scale to multiple hosts: Dokku, Compose, Krane, Deis, DockerUI, Shipyard, Drone, Jenkins... and, of course, the Docker client itself.
Like other Docker projects, Swarm follows the "batteries included but removable" principle. It ships with a simple scheduling backend out of the box, and as initial development settles, an API will develop to enable pluggable backends. The goal is to provide a smooth out-of-box experience for simple use cases, and allow swapping in more powerful backends, like Mesos, for large scale production deployments.
Pre-requisites for running Swarm
You must install Docker 1.4.0 or later on all nodes. While each node's IP need not be public, the Swarm manager must be able to access each node across the network.
To enable communication between the Swarm manager and the Swarm node agent on each node, each node must listen to the same network interface (tcp port). Follow the set up below to ensure you configure your nodes correctly for this behavior.
Note: Swarm is currently in beta, so things are likely to change. We don't recommend you use it in production yet.
WHAT IS DOCKER SWARM?
WHY USE DOCKER SWARM?
OK, HOW DO WE USE DOCKER SWARM?I started with a t2.micro instance on AWS running Ubuntu 14.04. From there you’ll need to install Docker Swarm and since it’s still pre-beta they’re not offering binaries yet.
The easiest way to get started with Swarm is to use the official Docker image.
docker pull swarm
Set up Swarm nodes
Each swarm node will run a swarm node agent. The agent registers the referenced Docker daemon, monitors it, and updates the discovery backend with the node's status.
The following example uses the Docker Hub based
- Create a Swarm cluster using the
bash $ docker run --rm swarm create 6856663cdefdec325839a4b7e1de38e8 # <- this is your unique <cluster_id>The create command returns a unique cluster id (
cluster_id). You'll need this id when starting the Swarm agent on a node.
- Log into each node and do the following.
- Start the docker daemon with the
-Hflag. This ensures that the docker remote API on Swarm Agents is available over TCP for the Swarm Manager.
$ docker -H tcp://0.0.0.0:2375 -d
- Add nodes to your swarm.Register the Swarm agents to the discovery service. The node's IP must be accessible from the Swarm Manager. Use the following command and replace with the proper
cluster_idto start an agent:
docker run -d swarm join --addr=<node_ip:2375> token://<cluster_id>For example:
bash $ docker run -d swarm join --addr=172.31.40.100:2375 token://6856663cdefdec325839a4b7e1de38e8
- Start the Swarm manager on any machine or your laptop. The following command illustrates how to do this:
docker run -d -p <swarm_port>:2375 swarm manage token://<cluster_id>
- Once the manager is running, check your configuration by running
docker infoas follows:
docker -H tcp://<manager_ip:manager_port> infoFor example, if you run the manager locally on your machine:
bash $ docker -H tcp://0.0.0.0:2375 info Containers: 0 Nodes: 3 agent-2: 172.31.40.102:2375 └ Containers: 0 └ Reserved CPUs: 0 / 1 └ Reserved Memory: 0 B / 514.5 MiB agent-1: 172.31.40.101:2375 └ Containers: 0 └ Reserved CPUs: 0 / 1 └ Reserved Memory: 0 B / 514.5 MiB agent-0: 172.31.40.100:2375 └ Containers: 0 └ Reserved CPUs: 0 / 1 └ Reserved Memory: 0 B / 514.5 MiBIf you are running a test cluster without TLS enabled, you may get an error. In that case, be sure to unset
$ unset DOCKER_TLS_VERIFY
Using the docker CLI
You can now use the regular
dockerCLI to access your nodes:
docker -H tcp://<manager_ip:manager_port> info docker -H tcp://<manager_ip:manager_port> run ... docker -H tcp://<manager_ip:manager_port> ps docker -H tcp://<manager_ip:manager_port> logs ...
List nodes in your cluster
You can get a list of all your running nodes using the
`docker run --rm swarm list token://<cluster_id>` <node_ip:2375>
$ docker run --rm swarm list token://6856663cdefdec325839a4b7e1de38e8 172.31.40.100:2375 172.31.40.101:2375 172.31.40.102:2375
Swarm supports TLS authentication between the CLI and Swarm but also between Swarm and the Docker nodes. However, all the Docker daemon certificates and client certificates must be signed using the same CA-certificate.
In order to enable TLS for both client and server, the same command line options as Docker can be specified:
swarm manage --tlsverify --tlscacert=<CACERT> --tlscert=<CERT> --tlskey=<KEY> [...]
Please refer to the Docker documentation for more information on how to set up TLS authentication on Docker and generating the certificates.
Note: Swarm certificates must be generated with
extendedKeyUsage = clientAuth,serverAuth.
See the Discovery service document for more information.