Today in Swarm Week, we’re getting more advanced with Swarm. In addition to orchestration tutorial video featuring Jérôme Petazzoni, we wanted to share some tips for you to try as you start getting familiar with creating and using Swarm clusters.
Tip 1: Labels Cheat Sheet
Each Docker Engine can be assigned one or more arbitrary string labels, like
disk=ssd. After that, you can include the same label specifier in your
docker run commands as a constraint that controls where your container is scheduled.
If you need a quick cheat sheet to remind you how to use labels and constraints, follow this pattern.
On one of your Engines:
docker daemon --label disk=ssd
On another Engine:
docker daemon --label disk=magnetic
Now run your containers like this:
docker run --label 'com.docker.swarm.constraints=["disk==ssd"]' -d busybox /bin/sh
Tip 2: How to enable reschedule on node failure (new in Swarm 1.1)
In Swarm 1.1 release, we introduced a new feature that allows you to enable the rescheduling of containers to a healthy node if the node they are running on fails for whatever reason. This feature is currently experimental. Try out this feature with the instructions below.
Run Swarm manage like this:
docker run swarm --experimental manage [rest of your args]
docker run --label 'com.docker.swarm.reschedule-policies=["on-node-failure"]' -d busybox /bin/sh
Tip 3: Fun with Container IDs and Swarm IDs
Each container has an ID that will change if the container is rescheduled to a new node. But each container also has a
com.docker.swarm.id that will not change if the container is rescheduled to a new node. If you name your container, you can do the same thing with names. Name will not change on rescheduling.
Example of use:
docker run alpine sh ddsa097dsa8f.... #
If the container is rescheduled, container id (
ddsa097dsa8f...) will change but Swarm ID (
abcdef123) will not change.
Tip 4: Heartbeat intervals
The Docker Engine discovery heartbeat is a mechanism that the overlay networking module uses to determine that the Docker daemon on a remote host in the cluster is still functioning. You can specify the frequency of heartbeats in seconds. The default frequency is 20 seconds (meaning very rapid heartbeating), but for larger clusters we recommend that you use a longer value.
Overlay networking depends on host discovery. Host discovery in Docker engine depends on a key-value (KV) store. In an environment with a very large number of hosts, the more aggressive heartbeat interval influences the performance of different KV Stores. We added daemon configuration flags in v1.10 to ease the stress on KV Store due to host discovery watch and events. You can tweak this value up or down based on your own scale requirements – get more information on this flag here.
Tip 5: –subnet option gives you more IPs
If you are planning on running many containers in the same overlay network then you’ll want to make sure you have enough IP addresses available in that overlay network. Use the
`--subnet` option while creating the network:
docker network create -d overlay --subnet=22.214.171.124/8
With the above configuration, the network will have 1.7 million IP addresses.
If you want to restrict it to 65,000, then use
Note: I am using the 126.96.36.199 subnet as an example. You can choose to use anything that doesn’t conflict with the IP addresses in use in your environment.
Give these tips a try and get familiar with different configurations and settings to customize your cluster to your needs. And don’t forget to participate in our DockerCon ticket raffle! Share a picture or description of your Swarm with us on Twitter and tag @docker and #SwarmWeek for a chance to win a free ticket to DockerCon 2016 on June 19-21 in Seattle, WA.
Here are some additional resources on Docker Swarm:
- Get started by downloading Docker Swarm and read the docs
- Try Docker Swarm as part of Docker Datacenter
- Submit questions to Docker Forums or file issues in Github
- Contribute to the Docker Swarm project
- View the other Swarm Week Posts
Learn More about Docker
- New to Docker? Try our 10 min online tutorial
- Share images, automate builds, and more with a free Docker Hub account
- Read the Docker 1.10 Release Notes
- Subscribe to Docker Weekly
- Sign up for upcoming Docker Online Meetups
- Attend upcoming Docker Meetups
- Register for DockerCon 2016
- Watch DockerCon EU 2015 videos
- Start contributing to Docker