Meanwhile, follow along this presentation I made during DockerCon 2018 https://youtu.be/V9fxU5zJKb4
This repo gives a few examples of patterns for how you might build Docker Swarm clusters with all the bells and whistles you would need in a real world setup. Note I have a course on Swarm for $10 on Udemy.
A Docker Swarm cluster needs more then just your app running, it often needs at least these additional services:
This demo is meant for you to git clone
and run locally to help you learn the tools and methods for building a complete Docker Swarm cluster.
This repo holds two deployment examples for Docker Swarm
The EE stack requires at least a trial license to deploy.
You can do all this locally on a single node or optionally using Docker Machine to multi-node clusters.
The scripts and compose/stack files use variables to make this demo easier to get started. Set these at your shell before running commands
# for Digital Ocean docker-machine driver
SSH_FINGERPRINT #fingerprint used to match your SSH key to Digital Ocean's
DO_SIZE #instance size for Digital Ocean to use for docker-machine
DO_TOKEN #Digital Ocean API token for creating/deleting droplets
# for Digital Ocean block storage
REXRAY_DO_TOKEN #Digital Ocean API token so RexRay can create storage volumes, can be same as DO_TOKEN
Just have Docker installed, either via Docker for Windows/Mac or on Linux. See my YouTube videos on the proper way to setup your OS for Docker using downloads from store.docker.com.
Then just create a single-node Swarm in that engine:
docker swarm init
./create-servers.sh
gives example docker-machine commands for creating 3 nodes in various VM environments including locally with VirtualBox, Hyper-V, and in the cloud using Digital Ocean.
./enable-monitoring.sh
simply overwrite /etc/docker/daemon.json
(we assume it doesn't exist) with two options to enabling the metrics endpoint, which will help Prometheus with more metrics later.
{
"metrics-addr" : "0.0.0.0:9323",
"experimental" : true
}
./create-swarm.sh
gives example docker-machine ssh commands for docker swarm init
and join
operations.
After this finishes, if you're using my docker-machine example you can connect to Docker TLS endpoint on node1 via:
docker-machine env dvc1
and then copy/paste the last line of output for your OS.
Create a docker secret using the REXRAY_DO_TOKEN
environment variable you set earlier.
echo $REXRAY_DO_TOKEN | docker secret create rexray_do_token -
From this point on, everything is in stack files! No custom node config's needed. 🎉
docker stack deploy -c stack-rexray.yml rexray
This sets up a global service to run a docker command against the host docker socket via bind-mount to install the storage driver for your cloud. Change the driver name to your cloud or docker volume storage plug-in vendor. This method of wrapping swarm-exec in a global mode service also means any new nodes to join the Swarm later will get the driver installed.
The above shows off how you can use swarm-exec utility to run a command (even a docker host command) on a set of nodes
Simple Proxy: docker stack deploy -c stack-proxy.yml proxy
This sets up a simple single-container proxy using Swarms ingress routing mesh to reverse proxy ports 80 and 443. It's good for demos and personal setups but you'll likely want something more as you grow.
The above shows off how you can use a reverse proxy to control traffic to many web URL's via their DNS name, and also includes Let's Encrypt dynamic config and cert requests
Advanced Proxy: docker stack deploy -c stack-proxy-global.yml proxy
This example builds on the simple proxy and adds a global mode Traefik service for HA proxy, and also runs the 80/443 listeners on the host NIC for improved performance and gathering of real client IP's (it then uses overlay networks to talk to app services). For HA Traefik it needs a key/value store so this example uses a single Consul container with RexRay storage. Lastly, it enables a socat container to allow Traefik to run on worker nodes while it uses TCP to talk to the Swarm management API via socat redirect.
The above shows off how to use host NIC directly in a service to avoid routing mesh, how to encrypt a network with IPSec, and how to use socat to redirect a docker socket to the network so you can void putting management containers on managers.
docker stack deploy -c docker-elk/docker-stack.yml -c elk.override.yml elk
docker stack deploy -c swarmprom/docker-compose.yml prom
docker stack deploy -c stack-portainer.yml portainer
docker stack deploy -c stack-prune.yml prune
docker stack deploy -c stack-menu.yml menu
docker stack deploy -c stack-voting.yml vote
docker stack deploy -c stack-ghost.yml ghost
stack-visualizer.yml
early on to see how your stacks and services fill out your swarm on port 4040.docker stack deploy -c stack-visualizer.yml viz