16. Declarative service model
Service というものを定義するようになりました
名称、環境変数、CPU?メモリの制限、ログドライバ、ポートの公開、実行数、ローリング
アップデートのための設定など
これまで docker-compose.yml など外部で定義していたものを Docker Engine 内で保持
します
17. Service と Task
● Service を作成すると定義にしたがってコンテナが実行される
● この実行されたコンテナが Task
$ docker service create --name nginx --replicas 3 nginx:1.11
f4p4cot1s7nhsx6kahuqy10ou
$ docker service ls
ID NAME REPLICAS IMAGE COMMAND
f4p4cot1s7nh nginx 3/3 nginx:1.11
$ docker service ps nginx
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE
ERROR
9bbpm947yca9bf428e9r07nwe nginx.1 nginx:1.11 ip-192-168-54-4 Running Running about a minute ago
53e1tx2bnngxhrzx19pqszwpp nginx.2 nginx:1.11 ip-192-168-54-5 Running Running about a minute ago
a47go7z2wql2nvbv61hsigeys nginx.3 nginx:1.11 ip-192-168-54-6 Running Running about a minute ago
18. Scaling
Service ごとにいくつの Task(コンテナ)を実行したいか定義できます
定義数を変更すれば swarm manager が自動でタスクの追加、削除を行って希望の数を
維持します
$ docker service scale --help
Usage: docker service scale SERVICE=REPLICAS [SERVICE=REPLICAS...]
Scale one or multiple services
Options:
--help Print usage
19. Desired state reconciliation
The swarm manager node constantly monitors the cluster state and reconciles any
differences between the actual state your expressed desired state. For example, if
you set up a service to run 10 replicas of a container, and a worker machine
hosting two of those replicas crashes, the manager will create two new replicas to
replace the ones that crashed. The swarm manager assigns the new replicas to
workers that are running and available.
同じことの繰り返しなので省略
28. Rolling updates
アプリの更新時、少しずつ更新することが可能。Swarm manager は同時にいくつの task
を更新するか、それぞれの間隔をどうするか、失敗した場合にどうするかをコントロール
できます
$ docker service update --help
…
Options:
…
--update-delay duration Delay between updates
--update-failure-action string Action on update failure ()
--update-parallelism unit Maximum number of tasks updated simultaneously
(0 to update all at once) (default 1)
…
30. Docker 1.12 でできなくなったこと
● docker-compose で Swarm クラスタに対しての deploy
$ docker-compose up -d
WARNING: The Docker Engine you're using is running in swarm mode.
Compose does not use swarm mode to deploy services to multiple nodes in a swarm.
All containers will be scheduled on the current node.
To deploy your application across the swarm, use the bundle feature of the Docker
experimental build.
More info:
https://docs.docker.com/compose/bundles
Creating network "wordpress_default" with the default driver
Creating wordpress_db_1
Creating wordpress_wordpress_1
https://docs.docker.com/compose/wordpress/
46. ECS / Task にするか Service にするかか
● Task Definition で定義したものを単純に N 個実行する
→ Task
● Task Definition で定義したものを N 個常に実行しておきたい、
Scale Up / Down させたい
→ Service
● Task Definition で定義したものを ELB で負荷分散させたい
→ Service
● Task Definition で定義したものを Rolling Update したい
→ Service