2016年2月25日 星期四

docker swarm

Node and role:
* Manage: Swarm manager and consul server container are run on this server
* Node: Swarm agent is run on this server

Prerequisties:
* docker version 1.9 or above
* docker node has unique hostname (key-value store use it)
* docker node with linux kernel 3.16 or above
* key-value store (swarm support consul, etcd or zookeeper, here we use consul)
* Properly configured engine daemon (only on swarm nodes)
** -H unix:///var/run/docker.sock -H tcp://{{node_ip|0.0.0.0}}:2375 --cluster-advertise={{node_ip}}:2375 --cluster-sotre=consul:{{consul_ip}}:8500

First, start a consul server, the consul server must be accessed by all of the swarm nodes
Manage# docker run -d -p 8500:8500 progrium/consul -server -bootstrap

The run swarm agent and join current swam cluster
Node# docker run -d swarm join consul://{{consul_ip}}:8500 --advertise={{node_ip}}:2375

At last, you can manage your swarm cluster via container.
Start a swarm manage and expose the swarm API server.
(It can be any server, even on your laptop, the only requirement is it can access to key-value store and swarm nodes)
(Any machine)# docker run -d -p 3375:2375 swarm manage consul://{{consul_ip}}:8500

You can manage your swarm cluster through these two command as following:
* Method 1:
# docker -H {{swarm_manage}}:3375 
* Method 2:
export DOCKER_HOST={{swarm_manage}}:3375
docker