Skip to content

Build Docker Swarm Mode cluster running on Debian with Vagrant.

License

Notifications You must be signed in to change notification settings

siso/vagrant-docker-swarm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Docker Swarm Vagrant

Vagrantfile to stand up Docker Engine Swarm Mode cluster. It requires Docker 1.12+, and runs Debian.

Quickstart

Provision Docker Swarm cluster:

# stand up docker swarm cluster
AUTO_START_SWARM=true vagrant up

vagrant up would provision machines without creating Docker Swarm cluster.

SSH on manager and check Docker Swarm cluster:

# vagrant ssh $VAGRANT_NODE_NAME, e.g.:
vagrant ssh manager

# a few checks

# docker engine info
docker version
docker info

# check swarm
docker node list

# docker swarm logs
sudo tail -f /var/log/daemon.log

Optionally set up monitoring with Grafana, Prometheus & Co.:

/vagrant/setup-monitoring.sh

Links:

Tear cluster down and free resources on host:

vagrant destroy -f

Demo

UI

Visualizer

Run Visualizer:

docker run -it -d -p 5000:8080 -v /var/run/docker.sock:/var/run/docker.sock dockersamples/visualizer

Connect on host: http://localhost:5000

portainer

portainer Simple management UI for Docker http://portainer.io

docker run -d -p 9000:9000 --restart always -v /var/run/docker.sock:/var/run/docker.sock -v /opt/portainer:/data portainer/portainer

Connect on host: http://localhost:9000

Service

Run a single service, e.g.:

docker service create --name web -p 80:80 nginx

Connect to nginx:

Manage service:

# display service info
docker service inspect web

# scale service
docker service scale web=3

# tear service down
docker service rm web

Stack

Create docker-compose.yml:

version: "3"
services:
  web:
    image: nginx
    deploy:
      replicas: 3
      resources:
        limits:
          cpus: "0.1"
          memory: 50M
      restart_policy:
        condition: on-failure
    ports:
      - "8888:80"
    networks:
      - webnet
networks:
  webnet:

Deploy stack:

docker stack deploy -c docker-compose.yml webstack

Connect to nginx: http://localhost:8888

Manage stack:

docker stack ls
docker stack ps webstack

docker stack ps --format "{{.Name}}: {{.Image}} {{.Node}} {{.DesiredState}} {{.CurrentState}}" webstack

See --format documentation.

There are two ways to scale a service, either by persisting changes to docker-compose.yml file:

  • edit docker-compose.yml
  • run docker stack deploy -c docker-compose.yml webstack

or at runtime:

  • docker service scale webstack_web=6

Load-test, e.g.:

ab -n 10000 -c 100 -s 2 -k http://192.168.10.2:80/

⚠️ ab looks broken on OS X:

ab -n 100 -c 10 http://localhost:8080/
This is ApacheBench, Version 2.3 <$Revision: 1807734 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)...apr_socket_recv: Connection refused (61)

Examples

docker node list
docker ps
docker service create --name web -p 80:80 nginx
curl 192.168.10.2
docker service rm web
docker service scale web=6
watch -d -n1 docker ps

Suspend a node vagrant suspend worker1, simulate outage on one node. Docker Swarm auto-heals by adding missing containers on remaining nodes to keep web service up and running:

docker node list
watch -d -n1 docker ps
curl 192.168.10.2

FAQ

Docker Swarm IP:

$ docker node inspect self --format '{{ .Status.Addr  }}'

License

GPLv3

Author

Simone Soldateschi simone.soldateschi@gmail.com

Links

Credits

  • Docker Swarm Vagrant
    • Inspired by denverdino/docker-swarm-mode-vagrant and lowescott/learning-tools repos.

About

Build Docker Swarm Mode cluster running on Debian with Vagrant.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages