Need help with docker-swarm-demo?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

120 Stars 21 Forks 64 Commits 3 Opened issues


A demo of Docker Swarm

Services available


Need anything else?

Contributors list

# 63,288
1 commit
# 15,174
1 commit

Docker Swarm POC

This repository contains a POC of Docker Swarm configured in the following manner: - 3 Docker hosts (dockerhost[01:03]) - Run latest Docker daemon - Run a Docker Swarm daemon pointed at Consul - Run a Registrator daemon pointed at Consul - 1 Docker Swarm host (dockerswarm01) - Runs Docker Swarm and listens to the Docker port - Is the primary interface for the Docker cluster - Runs Consul - Consul provides service discovery via its key/value store - Web UI available at http://dockerswarm01/ui - Swarm path of http://dockerswarm01/swarm


There are a few requirements to get - Vagrant (latest): - Vagrant hosts plugin:

vagrant plugin install vagrant-hosts
- VirtualBox: or VMware: - Ansible:
brew install ansible
- SSHPass:
brew install
- /etc/hosts: Allows us to call things by hostname:
``` dockerswarm01 dockerhost01 dockerhost02 dockerhost03

How to use it

Everything can be tried out using Vagrant once the pre-reqs have been installed. Just follow these simple instructions:

# Stand up the environment and provision the hostfile entries
vagrant up

Update the /etc/hosts files on the VMs

vagrant provision --provision-with hosts

Set your env variables to point at Vagrant

source bin/env

Pull images down to the docker hosts.

cd ansible/ ansible-playbook vagrant_docker_images.yml

Interact with Docker as normal

docker ps docker run --rm -i -t ubuntu:latest /bin/bash


TLS is functional as long as Swarm is configured to use the

type of discovery. After generating the certificates, set the following variables for both the
groups to run TLS: - usetls: true - dockerport: 2376

The certificates can be generated and the cluster provisioned using the following commands. Please note: The PKI is included in .gitignore and so will need to be regenerated each time this repo is cloned. ```

Generate SSL


Provision the cluster

vagrant up

Set your env to Vagrant + TLS

source bin/env_tls

Pull images down to the docker hosts.

./bin/ ansible-playbook vagrantdockerimages.yml

Interact with the cluster

docker ps docker run --rm -i -t ubuntu:latest /bin/bash

### Swarm configuration
The Swarm daemon has a few configuration options that are available. They
- Discovery
- Scheduling
- TLS (config described above)

Swarm discovery

Swarm supports multiple discovery mechanisms including:

  • File (supported here)
  • Consul (supported here)
  • EtcD
  • Zookeeper
  • Hosted service (Docker Hub?)

File Discovery: Uses a static file with a list of Docker hosts. Swarm is pointed at this list and will create a cluster based on it's contents. This is the most basic discovery method and is enabled by default in this project (though currently the project is configured for Consul). The format of the list should be the following:

http://< hostname1 >:< port > http://< hostname2 >:< port > http://< hostname3 >:< port > http://< hostname4 >:< port > ```

Consul Discovery: This configuration mode is what this project is configured to use currently. It relies on Consul's key/value store being located on the Swarm host (dockerswarm01) at /swarm. In addition to maintaining the Swarm cluster, this Consul host also is the endpoint Registrator uses for service discovery under the path /services. You can view the cluster in Consul at: http://dockerswarm01/ui/#/test/kv/swarm/

Swarm Scheduling

At this point in time, Swarm supports two scheduling modes with one in progress: - Binpacking: pack a machine based on a static set of resources - Random: Pick a host at random - Balanced: Pack machines evenly (In-Progress

Swarm uses the scheduling configuration in combination with tags in the Docker daemon's startup configs to enable control over how to pack the machines. You can edit the various tags on a machine-by-machine basis by editing the host specific configs found in

and then specifying a constraint. An example of a Docker run line for a host in the cluster would be:
docker --label zone=external \
  --label disk=ssd \
  -H tcp://

An example that will start an Nginx container on the above node through Swarm could be:

docker run -d \
  -p 80 \
  -e constraint:zone==external \
  -e constraint:disk==ssd \
  -t nginx:latest

The above configuration will start an Nginx server on a Docker host in the Swarm cluster that has been tagged with

. Since there are ports published, registrator will also pick this up and upsert a value into the
key in Consul with the value of "ipaddress:port" of the running container.

Included Projects

Registrator -

Docker Swarm -

Consul -

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.