This script uses docker-machine to provision a local virtual cluster in VirtualBox, starts docker swarm in the cluster, and installs the stack Portainer (http://portainer.io).
Besides, it creates a set of scripts to manage the created swarm cluster.
Linux host, docker, docker-machine and docker-machine-ipconfig (https://github.com/fivestars/docker-machine-ipconfig) to assign static IP addresses to the virtual machines.
# Cluster name
cluster="demo"
# Number of manager nodes in the swarm cluster
managers=1
# Number of worker nodes in the swarm cluster
workers=2
# Host only network in VirtualBox to connect the VMs
net="192.168.100.1/24"
# Directory to store generated cluster scripts
export CLUSTER_SCRIPTS_DIR=~/.docker/swarm
# Directory where required scripts can be found:
#
# create_swarm_cluster.sh
# docker-machine-ipconfig
BIN=~/bin/swarm
export PATH=$PATH:$BIN
# Memory to assign to manager VMs
export MANAGER_MEMORY=1024
# Memory to assign to worker VMs
export WORKER_MEMORY=1024
# Create the swarm cluster using VirtualBox
create_swarm_cluster $cluster $managers $workers $net
# List clusters
list_clusters
When the cluster is created and started, a directory ${CLUSTER_SCRIPTS_DIR}/${cluster} is created and contains the following scripts to manage the cluster:
stop_cluster.shto stop the clusterstart_cluster.shto start the clusterstatus_cluster.shto check the status of the clusteradd_worker.shto create and add a new worker node to the clusterrm_worker.shto delete a worker node from the cluster (this deletes the VM)rm_cluster.shto delete the whole cluster (deleting all the VMs)
The following image shows a screenshoot of Portainer deployed in the cluster:
