From bf79d66aa64d8b8b8f22a7b86215f67bceb77e14 Mon Sep 17 00:00:00 2001 From: Guillem Hernandez Sola Date: Wed, 13 Jun 2018 14:46:19 +0200 Subject: [PATCH] Added swarm --- swarm/README.md | 36 ++++++++++++++++++++++++++++++++++++ swarm/Vagrantfile | 20 ++++++++++++++++++++ swarm/docker_install.sh | 25 +++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100755 swarm/README.md create mode 100755 swarm/Vagrantfile create mode 100755 swarm/docker_install.sh diff --git a/swarm/README.md b/swarm/README.md new file mode 100755 index 0000000..3303e85 --- /dev/null +++ b/swarm/README.md @@ -0,0 +1,36 @@ +* to install Docker swarm container: + +```docker run swarm --help``` + +* To run the consul container on the manager node: + +```docker run -d -p 8500:8500 --name=consul progrium/consul -server -bootstrap``` + +* To run the swarm manage node on the master: + +```docker run -d -p 4000:4000 swarm manage -H :4000 --advertise 192.168.0.248:4000 consul://192.168.0.248:8500 ``` + +* To run swarm join on the agent2 + +```docker run -d swarm join --advertise=192.168.0.246:2375 consul://192.168.0.248:8500``` + +* To run swarm join on the agent3 + +```docker run -d swarm join --advertise=192.168.0.247:2375 consul://192.168.0.248:8500``` + +* see cluster status + +```docker -H :4000 info``` + +* Run on a container on your swarm cluster: + +```docker -H :4000 run -p 3000:3000 -d wardviaene/nodejs-demo``` + +* List containers: + +```docker -H :4000 ps``` + +* Connect to the nodejs-demo container + +```curl 192.168.0.247:3000``` + diff --git a/swarm/Vagrantfile b/swarm/Vagrantfile new file mode 100755 index 0000000..8ed1aeb --- /dev/null +++ b/swarm/Vagrantfile @@ -0,0 +1,20 @@ +Vagrant.configure(2) do |config| + config.vm.define "manager" do |manager| + manager.vm.box = "bento/ubuntu-18.04" + manager.vm.network "private_network", ip: "192.168.0.248" + manager.vm.hostname = "manager.example.com" + manager.vm.provision "shell", path: "docker_install.sh" + end + config.vm.define "agent1" do |agent1| + agent1.vm.box = "bento/ubuntu-18.04" + agent1.vm.network "private_network", ip: "192.168.0.247" + agent1.vm.hostname = "docker-agent1.example.com" + agent1.vm.provision "shell", path: "docker_install.sh" + end + config.vm.define "agent2" do |agent2| + agent2.vm.box = "bento/ubuntu-18.04" + agent2.vm.network "private_network", ip: "192.168.0.246" + agent2.vm.hostname = "docker-agent2.example.com" + agent2.vm.provision "shell", path: "docker_install.sh" + end +end diff --git a/swarm/docker_install.sh b/swarm/docker_install.sh new file mode 100755 index 0000000..ca87d0b --- /dev/null +++ b/swarm/docker_install.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -eux +apt-get update +apt-get install -y --no-install-recommends \ + apt-transport-https \ + ca-certificates \ + curl \ + software-properties-common \ + python-minimal zip python-simplejson \ + gnupg2 \ + software-properties-common +apt-get remove docker docker-engine docker.io +# install docker +curl -fsSL get.docker.com -o get-docker.sh +sh get-docker.sh +# install docker-compose +curl -L "https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && \ + chmod +x /usr/local/bin/docker-compose +# install docker-machine +curl -L "https://github.com/docker/machine/releases/download/v0.15.0/docker-machine-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-machine && \ + chmod +x /usr/local/bin/docker-machine +apt-get -y install linux-image-extra-$(uname -r) +usermod -aG docker vagrant +echo 'DOCKER_OPTS="-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock"' >> /etc/default/docker +service docker restart