Created
December 8, 2017 12:18
-
-
Save d1ys3nk0/bff2317d8f631cb475201267a75c6627 to your computer and use it in GitHub Desktop.
Docker Swarm Cluster
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
MACHINES = { | |
'node01' => '192.168.56.101', | |
'node02' => '192.168.56.102' | |
}.freeze | |
Vagrant.configure(2) do |config| | |
config.vm.box = 'ubuntu/trusty64' | |
config.vm.provider 'virtualbox' do |provider| | |
provider.memory = 512 | |
provider.cpus = 1 | |
end | |
MACHINES.each do |name, ip| | |
config.vm.define(name) do |host| | |
host.vm.hostname = "#{name}.dev" | |
host.vm.network 'private_network', ip: ip | |
host.vm.provision :shell, inline: %( | |
#!/bin/bash | |
export DEBIAN_FRONTEND=noninteractive | |
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common | |
sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual | |
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - | |
sudo apt-key fingerprint 0EBFCD88 | |
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | |
sudo apt-get update | |
sudo apt-get install -y docker-ce | |
sudo usermod -a -G docker ${USER} | |
docker version | |
) | |
if name == MACHINES.keys.first | |
host.vm.provision :shell, inline: "docker swarm init --advertise-addr #{ip}" | |
host.vm.provision :shell, inline: 'docker swarm join-token -q worker > /vagrant/.vagrant/swarm-token' | |
else | |
host.vm.provision :shell, inline: "docker swarm join --token `cat /vagrant/.vagrant/swarm-token` #{MACHINES.values.first}:2377" | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment