Quick How-to to set up Swarm cluster

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

# Hosts
node1 ansible_host=
node2 ansible_host=
node3 ansible_host=


2.On node manager ( run :

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

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

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


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"


And here is the bootstrap.sh script content


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;
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;

cat <>/var/www/ovpn/demoapp_uwsgi.ini
#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

/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 !