1. zERobYTezERo

    Posted

    zERobYTezERo
Changes in title
+ELB+Swarm+Compose+Consul+Registratorで夢は叶うのか(1)
Changes in tags
Changes in body
Source | HTML | Preview

目的

ELB配下に複数のUbuntuインスタンスを置き、それぞれのNginxに対してConsul+Registratorを使ってコンテナを自動でぶら下げたい

コンテナの制御はSwarm+Composeで実現したい
さて夢は叶うのだろうか

環境

ホスト名 IPアドレス
docker00 10.10.0.49
docker01 10.10.0.50
docker02 10.10.0.51

Amazon VPC内にUbuntuで作成した

Docker導入x3

$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9

$ sudo sh -c "echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
$ sudo apt-get update
$ sudo apt-get install -y lxc-docker

Docker Remote APIの有効化

DOCKER_OPTS="-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock"

再起動

$ sudo service docker restart

API確認

2375/tcpをそれぞれ疎通確認

$ docker -H 10.10.0.49:2375 ps -a
$ docker -H 10.10.0.50:2375 ps -a
$ docker -H 10.10.0.51:2375 ps -a

Docker-Compose導入x3

$ sudo curl -L https://github.com/docker/compose/releases/download/1.1.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

$ sudo chmod +x /usr/local/bin/docker-compose

Swarm導入

トークンの取得

どれか1台で実行して取得

# docker run --rm swarm create
Unable to find image 'swarm:latest' locally
511136ea3c5a: Pull complete
ae115241d78a: Pull complete
f49087514537: Pull complete
fff73787bd9f: Pull complete
97c8f6e912d7: Pull complete
33f9d1e808cf: Pull complete
62860d7acc87: Pull complete
bf8b6923851d: Pull complete
swarm:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.
Status: Downloaded newer image for swarm:latest
c8e73fe4b34710e915089846d21aef1f

Swarmエージェントとホストの起動

docker00にはマネージャとエージェントを入れ、docker01,docker02にはエージェントだけを起動させてみる

docker00~02
# mkdir -p /root/docker-host/boot
# cd /root/docker-host/boot
# nano docker-compose.yml

Docker00用

docker-compose.yml
swarmagent:
  image: swarm:latest
  command: join --addr=10.10.0.49:2375 token://c8e73fe4b34710e915089846d21aef1f

swarmmanager:
  image: swarm:latest
  command: manage token://c8e73fe4b34710e915089846d21aef1f
  ports:
  - "2380:2375"

Docker01用

docker-compose.yml
swarmagent:
  image: swarm:latest
  command: join --addr=10.10.0.50:2375 token://c8e73fe4b34710e915089846d21aef1f

Docker02用

docker-compose.yml
swarmagent:
  image: swarm:latest
  command: join --addr=10.10.0.51:2375 token://c8e73fe4b34710e915089846d21aef1f

それぞれを立ち上げよう

# docker-compose up -d
Creating boot_swarmagent_1...
Creating boot_swarmmanager_1...
# docker-compose ps
       Name                      Command               State           Ports
-------------------------------------------------------------------------------------
boot_swarmagent_1     /swarm join --addr=10.10.0 ...   Up      2375/tcp
boot_swarmmanager_1   /swarm manage token://c8e7 ...   Up      0.0.0.0:2380->2375/tcp

Docker00はこんな感じになる

ノードが全部検出されているか確認

# docker -H tcp://localhost:2380 info
Containers: 6
Nodes: 3
 ip-10-10-0-51: 10.10.0.51:2375
  └ Containers: 1
  └ Reserved CPUs: 0 / 1
  └ Reserved Memory: 0 B / 1.954 GiB
 ip-10-10-0-50: 10.10.0.50:2375
  └ Containers: 1
  └ Reserved CPUs: 0 / 1
  └ Reserved Memory: 0 B / 1.954 GiB
 ip-10-10-0-49: 10.10.0.49:2375
  └ Containers: 4
  └ Reserved CPUs: 0 / 1
  └ Reserved Memory: 0 B / 1.954 GiB

素敵じゃないか

次の記事ではこれにConsulをかぶせていく。