The Go Blog

Docker Swarm

bantana
28 June 2015

introduction

swarm need tcp listen

DOCKER_OPTS:

-H 0.0.0.0:2375

create a token as clusterID

TOKEN:

$ docker run --rm hypriot/rpi-swarm create

21a4801b48989ff96dba6e8b44a99a64  <-- token as clusterID

start node

$ docker run --name="swarm-agent" -d hypriot/rpi-swarm join --addr=`ip -f inet addr show dev br0|grep inet|awk '{print $2}'|sed -e 's#/.*##'`:2375 token://${TOKEN}

可以用docker ps 来检查

Starting the Manager

$ docker run -d --name=swarm-manager -p 3456:2375 hypriot/rpi-swarm manage token://${TOKEN}

Discovery node

$ docker run --rm  hypriot/rpi-swarm list token://${TOKEN}

every time run this command if you join a node

use 3456 port run docker command

$ docker -H tcp://localhost:3456 ps

$ docker -H tcp://localhost:3456 info

example:

three rpi2, run docker 1.6.2-2, hypriot/rpi-swarm

manager:

192.168.88.54

node:

192.168.88.51, 192.168.88.53, 192.168.88.54

1. on 192.168.88.54 manager

$ docker run --rm hypriot/rpi-swarm create

21a4801b48989ff96dba6e8b44a99a64  <-- token as clusterID

2. start node on 192.168.88.54

$ docker run --name="swarm-agent" -d hypriot/rpi-swarm join --addr=`ip -f inet addr show dev br0|grep inet|awk '{print $2}'|sed -e 's#/.*##'`:2375 token://21a4801b48989ff96dba6e8b44a99a64
15e7a784b81b50e1136a4ac06a1dbd30204badc63832c53e653e29938c5cc7a2

3. start manager on 192.168.88.54

$ docker run -d --name=swarm-manager -p 3456:2375 hypriot/rpi-swarm manage token://21a4801b48989ff96dba6e8b44a99a64
7e56fddb7af73b274a76221a4d5e728670b0df374a5b51259e6891888deab2c5

4. Discovery

$ docker run --rm  hypriot/rpi-swarm list token://21a4801b48989ff96dba6e8b44a99a64
time="2015-06-29T05:25:58Z" level=fatal msg="Get https://discovery-stage.hub.docker.com/v1/clusters/21a4801b48989ff96dba6e8b44a99a64: dial tcp: i/o timeout"

$ docker run --rm  hypriot/rpi-swarm list token://21a4801b48989ff96dba6e8b44a99a64
192.168.88.54:2375

5. start node on 192.168.88.53

$ docker run --name="swarm-agent" -d hypriot/rpi-swarm join --addr=`ip -f inet addr show dev br0|grep inet|awk '{print $2}'|sed -e 's#/.*##'`:2375 token://21a4801b48989ff96dba6e8b44a99a64
64d76d9cf1394c8cf01b11ca8e89685a3686b019c6dc10e5b63f229bb05fae1a

6. repeat Discovery

$ docker run --rm  hypriot/rpi-swarm list token://21a4801b48989ff96dba6e8b44a99a6
time="2015-06-29T05:27:38Z" level=fatal msg="Get https://discovery-stage.hub.docker.com/v1/clusters/21a4801b48989ff96dba6e8b44a99a64: dial tcp: i/o timeout"

$ docker run --rm  hypriot/rpi-swarm list token://21a4801b48989ff96dba6e8b44a99a64
192.168.88.54:2375
192.168.88.53:2375

7. start node on 192.168.88.51

$ docker run --name="swarm-agent" -d hypriot/rpi-swarm join --addr=`ip -f inet addr show dev br0|grep inet|awk '{print $2}'|sed -e 's#/.*##'`:2375 token://21a4801b48989ff96dba6e8b44a99a64
64d76d9cf1394c8cf01b11ca8e89685a3686b019c6dc10e5b63f229bb05fae1a

8. repeat Discovery

$ docker run --rm  hypriot/rpi-swarm list token://21a4801b48989ff96dba6e8b44a99a64
192.168.88.51:2375
192.168.88.54:2375
192.168.88.53:2375

9. The name of container is change to <hostName>:<containerName>

$ docker -H localhost:3456 ps -a
CONTAINER ID        IMAGE                      COMMAND                CREATED             STATUS                         PORTS                          NAMES
64d76d9cf139        hypriot/rpi-swarm:latest   "/swarm join --addr=   18 minutes ago      Up 18 minutes                  2375/tcp                       pi2/swarm-agent
73e86600f0ad        hypriot/rpi-swarm:latest   "/swarm join --addr=   19 minutes ago      Up 18 minutes                  2375/tcp                       api/swarm-agent
7e56fddb7af7        hypriot/rpi-swarm:latest   "/swarm manage token   21 minutes ago      Up 21 minutes                  192.168.88.54:3456->2375/tcp   raspberrypi/swarm-manager
15e7a784b81b        hypriot/rpi-swarm:latest   "/swarm join --addr=   22 minutes ago      Up 22 minutes                  2375/tcp                       raspberrypi/swarm-agent
be89da36e3a2        jessie:dockerbuild         "/usr/sbin/sshd -D"    3 hours ago         Up 3 hours                     22/tcp                         raspberrypi/dockerbuild
9b51df4e978c        jessie:clang               "/usr/sbin/sshd -D"    44 hours ago        Up 17 hours                    22/tcp                         pi2/mygo
c11524576bfc        rpi2_ssh:latest            "/usr/sbin/sshd -D"    2 days ago          Exited (0) About an hour ago                                  api/ss
652b9e2fb022        rpi2_ssh:latest            "/usr/sbin/sshd -D"    2 weeks ago         Exited (0) About an hour ago                                  api/golang
918dd0b63b15        rpi2_ssh:latest            "/usr/sbin/sshd -D"    2 weeks ago         Exited (128) 11 days ago       22/tcp                         api/ruby

$ docker -H 192.168.88.54:3456 info
Containers: 9
Strategy: spread
Filters: affinity, health, constraint, port, dependency
Nodes: 3
 api: 192.168.88.53:2375
  └ Containers: 4
  └ Reserved CPUs: 0 / 4
  └ Reserved Memory: 0 B / 971.3 MiB
 pi2: 192.168.88.51:2375
  └ Containers: 2
  └ Reserved CPUs: 0 / 4
  └ Reserved Memory: 0 B / 1022 MiB
 raspberrypi: 192.168.88.54:2375
  └ Containers: 3
  └ Reserved CPUs: 0 / 4
  └ Reserved Memory: 0 B / 972.3 MiB

Related articles