Quick How-to to set up Swarm cluster

1.Define a file hosts with the entries below, where : 192.168.1.3 is the IP address of the node manager, and 192.168.1.5 and 192.168.1.6 are simple nodes.

# Hosts
node1 ansible_host=192.168.1.3
node2 ansible_host=192.168.1.5
node3 ansible_host=192.168.1.6

[swarm]
node1
node2
node3

2.On node manager (192.168.1.103) run :

$ docker swarm init 3. Run the docker swarm join command on the rest of nodes, using ansible

$ ansible swarm:’!192.168.1.103′ -m shell -a ‘docker swarm join –token SWMTKN-1-32c9u5o0y7gbp3zg8wlvkacbcz0jcwnfgzyhitn5xk8v3gi7s5-2pyej0kduwv6kmx7ynjjvxnhl 192.168.1.103:2377′

The token WMTKN-1-32c9u5o0y7gbp3zg8wlvkacbcz0jcwnfgzyhitn5xk8v3gi7s5-2pyej0kduwv6kmx7ynjjvxnhl should depends on the return of the command : dockers swarm init.

4.Open 2377 TCP port on your firewall if you have one activated.

$ ufw allow 2377/tcp

5.Create the service :

$ docker service create –name hello-world –replicas 3 -p 80:80 dockercloud/hello-world

Quick How-to to set up Swarm cluster

Build nginx flask vagrant vbox on windows

Before this post I wrote and article on how to serve flask on ubuntu.
I share with you my first contact with vagrant, on a windows box I build a virtualbox vm that run nginx, and a flask “hello world” application.

here the Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|

hostname = "propus"
locale = "en_GB.UTF.8"

# Box
config.vm.box = "ubuntu/trusty64"

# Shared folders
config.vm.synced_folder ".", "/var/www/ovpn"

# Port forwarding
config.vm.network :forwarded_port, guest: 80, host: 8080

# Setup
config.vm.provision :shell, :inline => "touch .hushlogin"
config.vm.provision :shell, :inline => "hostnamectl set-hostname #{hostname} && locale-gen #{locale}"
config.vm.provision :shell, :inline => "apt-get update --fix-missing"
config.vm.provision :shell, :inline => "apt-get install -q -y g++ make git vim"

# Lang
config.vm.provision :shell, :inline => "apt-get install -q -y python python-dev python-distribute python-pip"

# nginx
config.vm.provision :shell, :inline => "apt-get install -q -y nginx"

config.vm.provision :shell, :path => "bootstrap.sh"

end

And here is the bootstrap.sh script content

#!/bin/bash

pip install virtualenv
mkdir -p /var/www/ovpn && cd /var/www/ovpn
mkdir /var/log/uwsgi/
virtualenv -p /usr/bin/python venv
source venv/bin/activate
pip install uwsgi
pip install flask
rm -f /etc/nginx/conf.d/default
cat <> /etc/nginx/conf.d/ovpn

server {
listen 80;
server_name 10.0.1.15;
charset utf-8;
client_max_body_size 75M;

location / { try_files $uri @ovpn; }
location @ovpn {
include uwsgi_params;
uwsgi_pass unix:/tmp/demoapp_uwsgi.sock;
}
}
EOF

cat <>/var/www/ovpn/demoapp_uwsgi.ini
[uwsgi]
#application's base folder
base = /var/www/ovpn

#python module to import
app = hello
module = %(app)

home = %(base)/venv
pythonpath = %(base)

#socket file’s location
socket = /tmp/%n.sock

#permissions for the socket file
chmod-socket = 666

#the variable that holds a flask application inside the module imported at line #6
callable = application

#location of log files
logto = /var/log/uwsgi/%n.log
EOF

/etc/init.d/nginx restart

Place the Vagrantfile and the bootstrap.sh in the same directory.
and from powershell console Run:

vagrant up

This will build the vm image. have a fun !

Build nginx flask vagrant vbox on windows