Skip to content

Instantly share code, notes, and snippets.

@ochinchina
Last active August 29, 2015 14:20
Show Gist options
  • Save ochinchina/cf0951d60c957d9392b2 to your computer and use it in GitHub Desktop.
Save ochinchina/cf0951d60c957d9392b2 to your computer and use it in GitHub Desktop.
try docker swarm in the docker 1.5 under ubuntu 14.04 LTS

###install the swarm

$ sudo docker pull swarm

###change the docker start options

change the DOCKER_OPTS in /etc/default/docker ( in ubuntu ) or /var/lib/apps/docker/1.6.1.002/etc/docker.conf ( in ubuntu core ) to "-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock"

###restart the docker

$ sudo service restart docker
or
$ sudo service restart docker_docker-daemon_1.6.1.002.service

###create a cluster

in one node, run the following command to create the cluster id

$ sudo docker run  --rm swarm create
1fa5a0b8f82cef18becdfc4f558d0daa

###join the swarm cluster

in each node, run:

$sudo docker run -d swarm join --addr=<node_ip>:2375 token://<cluster_id>

for example, in node 192.168.56.101, run following command:

$sudo docker run -d swarm join --addr=192.168.56.101:2375 token://1fa5a0b8f82cef18becdfc4f558d0daa

###start swarm manager in one cluster node

start the swarm manager in one cluster node:

$sudo docker  run -d -p <manager_port>:2375  swarm manage token://<cluster_id>

for example, run the swarm manager in the 192.168.56.101 with following command:

$sudo docker run -d -p 2377:2375 swarm manage token://1fa5a0b8f82cef18becdfc4f558d0daa

###run the docker command

$sudo docker -H tcp://<manager_ip:manager_port> <command>

In the above example, we can run the info command like:

$sudo docker -H 192.168.56.101:2377 info
Containers: 34
Strategy: spread
Filters: affinity, health, constraint, port, dependency
Nodes: 2
 ubuntu-server-1404-1: 192.168.56.104:2375
  └ Containers: 17
  └ Reserved CPUs: 524288 / 1
  └ Reserved Memory: 512 MiB / 2.053 GiB
 ubuntu-server-1404-2: 192.168.56.101:2375
  └ Containers: 17
  └ Reserved CPUs: 1572864 / 1
  └ Reserved Memory: 1.5 GiB / 2.053 GiB

you can run other docker commands use "sudo docker -H tcp://<manager_ip:manager_port> "

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment