Skip to content

Instantly share code, notes, and snippets.

@masato
Last active December 19, 2015 17:34
Show Gist options
  • Save masato/1311e1a40728d7efeb5c to your computer and use it in GitHub Desktop.
Save masato/1311e1a40728d7efeb5c to your computer and use it in GitHub Desktop.
IDCFクラウドのDebian JessieでMulti-Host Docker Networking - Part 2: Docker Swarmクラスタの作成 ref: http://qiita.com/masato/items/a047798e48ccc1e56eb8
#DOCKER_OPTS="--cluster-store=consul://localhost:8500 --cluster-advertise=eth0:2376"
DOCKER_OPTS="--cluster-store=consul://localhost:8500 --cluster-advertise=eth0:2376 -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock"
$ docker pull swarm
$ docker run -d \
--name swarm-manage \
-p 3333:2375 \
swarm \
manage \
consul://10.3.0.101:8500/swarm
$ docker \
run -d -it \
--name amb2 \
-h amb2 \
--net dn \
debian:jessie
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
adb34e982686 debian:jessie "/bin/bash" 40 seconds ago Up 39 seconds amb2
7c328c08df7a swarm "/swarm join --addr=1" 20 minutes ago Up 20 minutes 2375/tcp dreamy_liskov
397912e89a4d swarm "/swarm manage consul" 24 minutes ago Up 24 minutes 0.0.0.0:3333->2375/tcp swarm-manage
$ docker -H tcp://10.3.0.101:3333 ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
adb34e982686 debian:jessie "/bin/bash" 7 seconds ago Up 6 seconds minion-1/amb2
b505e4526019 debian:jessie "/bin/bash" 4 minutes ago Up 4 minutes minion-2/amb1
$ docker exec amb1 cat /etc/hosts
Error response from daemon: no such id: amb1
$ docker -H tcp://10.3.0.101:3333 exec amb1 cat /etc/hosts
192.168.0.2 amb1
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
192.168.0.3 amb2
192.168.0.3 amb2.dn
$ docker exec amb2 cat /etc/hosts
192.168.0.3 amb2
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
192.168.0.2 amb1
192.168.0.2 amb1.dn
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b505e4526019 debian:jessie "/bin/bash" About a minute ago Up About a minute amb1
ce9217effebd swarm "/swarm join --addr=1" 15 minutes ago Up 15 minutes 2375/tcp furious_leakey
$ docker -H tcp://10.3.0.101:3333 ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
adb34e982686 debian:jessie "/bin/bash" 2 minutes ago Up 2 minutes minion-1/amb2
b505e4526019 debian:jessie "/bin/bash" 6 minutes ago Up 5 minutes minion-2/amb1
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
62458254ec86 swarm "/swarm join --addr=1" 15 minutes ago Up 15 minutes 2375/tcp awesome_babbage
$ docker -H tcp://10.3.0.101:3333 ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
adb34e982686 debian:jessie "/bin/bash" 2 minutes ago Up 2 minutes minion-1/amb2
b505e4526019 debian:jessie "/bin/bash" 6 minutes ago Up 6 minutes minion-2/amb1
$ docker run -d \
swarm \
join \
--addr=10.3.0.101:2375 \
consul://10.3.0.101:8500/swarm
$ docker -H tcp://10.3.0.101:3333 info
Containers: 2
Images: 2
Role: primary
Strategy: spread
Filters: health, port, dependency, affinity, constraint
Nodes: 1
minion-1: 10.3.0.101:2375
└ Status: Healthy
└ Containers: 2
└ Reserved CPUs: 0 / 2
└ Reserved Memory: 0 B / 8.202 GiB
└ Labels: executiondriver=native-0.2, kernelversion=3.16.0-4-amd64, operatingsystem=Debian GNU/Linux 8 (jessie), storagedriver=aufs
CPUs: 2
Total Memory: 8.202 GiB
Name: 397912e89a4d
$ docker pull swarm
$ docker run -d \
swarm \
join \
--addr=10.3.0.102:2375 \
consul://10.3.0.102:8500/swarm
$ docker -H tcp://10.3.0.101:3333 info
Containers: 3
Images: 4
Role: primary
Strategy: spread
Filters: health, port, dependency, affinity, constraint
Nodes: 2
minion-1: 10.3.0.101:2375
└ Status: Healthy
└ Containers: 2
└ Reserved CPUs: 0 / 2
└ Reserved Memory: 0 B / 8.202 GiB
└ Labels: executiondriver=native-0.2, kernelversion=3.16.0-4-amd64, operatingsystem=Debian GNU/Linux 8 (jessie), storagedriver=aufs
minion-2: 10.3.0.102:2375
└ Status: Healthy
└ Containers: 1
└ Reserved CPUs: 0 / 2
└ Reserved Memory: 0 B / 8.202 GiB
└ Labels: executiondriver=native-0.2, kernelversion=3.16.0-4-amd64, operatingsystem=Debian GNU/Linux 8 (jessie), storagedriver=aufs
CPUs: 4
Total Memory: 16.4 GiB
Name: 397912e89a4d
$ docker run -d \
swarm \
join \
--addr=10.3.0.103:2375 \
consul://10.3.0.103:8500/swarm
$ docker -H tcp://10.3.0.101:3333 info
Containers: 4
Images: 6
Role: primary
Strategy: spread
Filters: health, port, dependency, affinity, constraint
Nodes: 3
minion-1: 10.3.0.101:2375
└ Status: Healthy
└ Containers: 2
└ Reserved CPUs: 0 / 2
└ Reserved Memory: 0 B / 8.202 GiB
└ Labels: executiondriver=native-0.2, kernelversion=3.16.0-4-amd64, operatingsystem=Debian GNU/Linux 8 (jessie), storagedriver=aufs
minion-2: 10.3.0.102:2375
└ Status: Healthy
└ Containers: 1
└ Reserved CPUs: 0 / 2
└ Reserved Memory: 0 B / 8.202 GiB
└ Labels: executiondriver=native-0.2, kernelversion=3.16.0-4-amd64, operatingsystem=Debian GNU/Linux 8 (jessie), storagedriver=aufs
minion-3: 10.3.0.103:2375
└ Status: Healthy
└ Containers: 1
└ Reserved CPUs: 0 / 2
└ Reserved Memory: 0 B / 8.202 GiB
└ Labels: executiondriver=native-0.2, kernelversion=3.16.0-4-amd64, operatingsystem=Debian GNU/Linux 8 (jessie), storagedriver=aufs
CPUs: 6
Total Memory: 24.61 GiB
Name: 397912e89a4d
$ docker -H tcp://10.3.0.101:3333 network ls
NETWORK ID NAME DRIVER
b68b118036d2 minion-1/bridge bridge
f10c0f7978af dn overlay
636664a4f746 minion-1/docker_gwbridge bridge
5d0368bb1be6 minion-3/host host
d839af5031ca minion-3/bridge bridge
bc09b464b0c5 minion-1/host host
a67f3a364d5b minion-2/bridge bridge
63b1b125bd29 minion-2/docker_gwbridge bridge
b29394e7420d minion-2/none null
1d85b701a383 minion-2/host host
8a4889033015 minion-3/none null
87ac747fad87 minion-3/docker_gwbridge bridge
6e0cf0387184 minion-1/none null
$ docker -H tcp://10.3.0.101:3333 \
run -d -it \
--name amb1 \
-h amb1 \
--net dn \
debian:jessie
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment