Giter Club home page Giter Club logo

docker-swarm's Introduction

Vagrant Docker Swarm

Although Kubernetes has become the de facto standard for container orchestration we still find environments that use Docker Swarm mode. This repo provides the configuration to spin up a Docker Swarm mode cluster using Vagrant.

This repository was created for the purpose of being a platform for tonyskidmore/docker-swarm-monitoring.

Testing environment

The configuration in this repository is designed and tested to run on a Windows 10 system (tested on an Intel i7 laptop with 8GB RAM) using Vagrant, Docker Toolbox and VirtualBox.

Note: Docker Desktop is now the preferred method to install Docker support on WIndows 10 so it should work with that too but for my requirements, in this particular example, I needed to work with the older Docker Toolbox.

Tested versions of products (may work with different versions):

  • Windows 10 20H2
  • Docker Toolbox 19.03.1
  • VirtualBox 6.1.16 (updated after installing Docker Toolbox)
  • Vagrant - Windows 64-bit 2.2.13
  • Git for Windows 64-bit 2.29.2

Architecture layout

Alt text

In the above diagram we can see that after deployment we will have a Docker Swarm mode 3-node cluster with a single manager and 2 x worker nodes. The design is as simple as possible to demonstrate some higher level concepts of working with Swarm and purposely avoids production level aspects such as TLS certificates, security and high availability. All that we want for our purposes is a simple 3-node cluster.

Spinning up the environment

The following steps will bring up the Docker swarm mode cluster once you have installed all of the products detailed in the Testing environment section. Depending on the speed of your system and Internet connection the environment should hopefully be up and running in around an hour or so.

mkdir \vagrant
cd \vagrant
git clone https://github.com/tonyskidmore/docker-swarm.git
cd docker-swarm
vagrant up

Post-provisioning snapshots

It can be useful to take snapshots of the cluster nodes pre-deployment of services as a quicker method to rolling back to a pristine state, rather than having to vagrant destroy and then vagrant up. I generally prefer to take offline snapshots and to do this you could perform the following commands:

cd \vagrant\docker-swarm

# shutdown cluster nodes
vagrant halt

# snapshot all nodes
1..3 | % { & vagrant snapshot save "docker-swarm-0$_" "pre-deployment" }

# bring up cluster again
vagrant up

To restore the snapshots perform that same actions above but replace the second step with:

# snapshot restore all nodes
1..3 | % { & vagrant snapshot restore "docker-swarm-0$_" "pre-deployment" --no-start }

Accessing the environment from the Windows host

Now that the environment has been deployed the Docker Swarm mode can be accessed from the Windows host system. Run Windows PowerShell and enter the following commands:

$env:DOCKER_HOST="192.168.217.133:2375"
$env:DOCKER_TLS_VERIFY=""
docker node ls

Note: The DOCKER_HOST and DOCKER_TLS_VERIFY environment variable commands will need to be set on each new PowerShell session that is opened. These commands tell the docker command to connect to our manager node and not to use TLS.

Example expected output:

ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
ty3mfoy14ldrpj4q5vsf5rpjp *   docker-swarm-01     Ready               Active              Leader              19.03.13
lrqp5wvpf978iq94du4ccr83i     docker-swarm-02     Ready               Active                                  19.03.13
qwcz1i9xg5v3f9cav9ba39zvf     docker-swarm-03     Ready               Active                                  19.03.13

Should you wish to SSH into any of the Docker Swarm mode nodes you can use the vagrant ssh <nodename> command. For example, to SSH into our manager node:

cd \vagrant\docker-swarm
vagrant ssh docker-swarm-01
[vagrant@docker-swarm-01 ~]$

Stopping and starting the environment

When the test cluster is not being actively used, the nodes can be suspended and resumed at will. This can be done by moving to the location of the vagrant file and issuing the suspend and resume commands:

cd \vagrant\docker-swarm

# suspend our docker swarm nodes
vagrant suspend

# resume our docker swarm nodes
vagrant resume

Alternatively the VMs can be stopped and started:

cd \vagrant\docker-swarm

# shutdown our docker swarm nodes
vagrant halt

# start up docker swarm nodes
vagrant up

Destroying the environment

Once testing has been completed the Docker swarm mode cluster can be destroyed by running the following commands:

cd \vagrant\docker-swarm
vagrant destroy -force

Learning material

Swarm mode overview
Getting Started with Docker Swarm Mode by Wes Higbee

docker-swarm's People

Contributors

tonyskidmore avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.