Dockerの概念図

Dockerを使っている中で、多くの概念があり混乱しそうなのでまとめておく。引用部の周囲の文章は、引用の翻訳でない

チュートリアル

docs.docker.com

全体像

f:id:babyron64:20171114185543p:plain

大雑把に言って、コンテナ->サービス->スタックという階層構造(hierarchy)になっている。

サービス (service)

f:id:babyron64:20171114185548p:plain

サービスは、一つのイメージしか実行できないが、一つのイメージから作られたレプリカを複数個含むことができる。また、サービスはコンテナの実行状態を設定する。実行時には、サービスが設定されている状態になるように調整(orchestration)される。

例えば、三つの複製(replica)を作るように設定されていた場合、サービスを開始した時に三つの複製が作られるのだが、しばらくして、そのうちの一つがエラーで止まってしまったとする。すると、新たな複製が自動的に作られ、複製が三つある状態が保たれる。

Services are really just “containers in production.” A service only runs one image, but it codifies the way that image runs—what ports it should use, how many replicas of the container should run so the service has the capacity it needs, and so on. https://docs.docker.com/get-started/part3/

スタック (stack)

f:id:babyron64:20171114185552p:plain

スタックは、サービスの集合。docker-composeコマンドで、Docker-compose.ymlファイルから生成できる。他の方法もあるらしいが、ここでは割愛。

A stack is a collection of services that make up an application in a specific environment. https://docs.docker.com/docker-cloud/apps/stack-yaml-reference/

docker-compose.ymlに似たものとして、docker-cloud.ymlがあるが、これらは別物。docker-cloud.ymlはdocker-compose.ymlをdocker cloud用に多少拡張したものっぽいが、実際どうかは詳しく調べていない。

A stack file is a file in YAML format that defines one or more services, similar to a docker-compose.yml file for Docker Compose but with a few extensions. The default name for this file is docker-cloud.yml. https://docs.docker.com/docker-cloud/apps/stack-yaml-reference/

スワーム (swarm)

f:id:babyron64:20171114185556p:plain

swarmは"群れ"という意味の英語。その名の通り、docker hostの集まり。これらのホストを使って、コンテナの実行を分散させる。それぞれのホストは、nodeと呼ばれる。ノードには、マネージャーとワーカーの二種類あり、一つのノードが両方兼任することもできる。swarmを使うには、専用のコマンドを使ってホストをswarm modeにする必要がある。

A swarm consists of multiple Docker hosts which run in swarm mode and act as managers (to manage membership and delegation) and workers (which run swarm services). A given Docker host can be a manager, a worker, or perform both roles. https://docs.docker.com/engine/swarm/key-concepts/

ノード (node)

f:id:babyron64:20171114192132p:plain

ノードには、マネージャーノードによってタスクが割り当てられる。各タスクは一つのコンテナを実行し、コンテナで実行エラーなどが起きたら終了する。

In the swarm mode model, each task invokes exactly one container. https://docs.docker.com/engine/swarm/how-swarm-mode-works/services/#tasks-and-scheduling

If the container fails health checks or terminates, the task terminates. https://docs.docker.com/engine/swarm/how-swarm-mode-works/services/#tasks-and-scheduling

A task is the atomic unit of scheduling within a swarm. When you declare a desired service state by creating or updating a service, the orchestrator realizes the desired state by scheduling tasks. https://docs.docker.com/engine/swarm/how-swarm-mode-works/services/#tasks-and-scheduling