Docker Stack入門

Docker入門シリーズ、続いてはStack。

docker stack

Manage Docker stacks The client and daemon API must both be at least 1.25 to use this command. Use the docker version command on the client to check your client and daemon API versions. Manage stacks.

バージョン1.25以上で利用可能で、Dockerスタック(複数のコンテナ)を管理する。

Stackコマンド

  • deploy
  • ls
  • ps
  • rm
  • services

deploy

docker stack deploy

Deploy a new stack or update an existing stack The client and daemon API must both be at least 1.25 to use this command. Use the docker version command on the client to check your client and daemon API versions. Create and update a stack from a compose file on the swarm.

Deploy a new stack or update an existing stack

新しいStackをデプロイしたり、既存のStackを更新したりする。

$ docker stack deploy -c docker-compose.yml [stack-name]

Compose-file

Compose file

These topics describe the Docker Compose implementation of the Compose format. Docker Compose 1.27.0+ implements the format defined by the Compose Specification. Previous Docker Compose versions have support for several Compose file formats – 1, 2, 2.x, and 3.x. The Compose specification is an unified 2.x and 3.x file format, aggregating properties accross these formats.

compose-spec/compose-spec

This document specifies the Compose file format used to define multi-containers applications. Distribution of this document is unlimited. The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119.

ls

docker stack ls

List stacks The client and daemon API must both be at least 1.25 to use this command. Use the docker version command on the client to check your client and daemon API versions. Lists the stacks. Note This is a cluster management command, and must be executed on a swarm manager node.

List stacks

Stack一覧を表示する。

$ docker stack ls
 NAME                SERVICES            ORCHESTRATOR
 webapp           2                   Swarm

–format

出力をフォーマットする。

PlaceholderDescription
.NameStack name
.ServicesNumber of services
.OrchestratorOrchestrator name
.NamespaceNamespace
$ docker stack ls --format "{{.Name}}: {{.Services}}"
 webapp: 2

ps

docker stack ps

List the tasks in the stack The client and daemon API must both be at least 1.25 to use this command. Use the docker version command on the client to check your client and daemon API versions. Lists the tasks that are running as part of the specified stack.

List the tasks in the stack

StackのTask一覧を表示する。

$ docker stack ps [stack-name]

–filter, -f

フィルタリングして表示する。

ExpressionSupported
id==xxxxSwarm / Kubernetes
name=xxxxSwarm / Kubernetes
node=xxxxSwarm / Kubernetes
desired-state=xxxxSwarm / Kubernetes
$ docker stack ps [stack-name] -f "name=web"

–format

出力をフォーマットする。

PlaceholderDescription
.IDTask ID
.NameTask name
.ImageTask image
.NodeNode ID
.DesiredStateDesired state of the task (runningshutdown, or accepted)
.CurrentStateCurrent state of the task
.ErrorError
.PortsTask published ports
$ docker stack ps [stack-name] --format '{{.ID}} {{.DesiredState}}'

rm

docker stack rm

Remove one or more stacks The client and daemon API must both be at least 1.25 to use this command. Use the docker version command on the client to check your client and daemon API versions. Remove the stack from the swarm. Note This is a cluster management command, and must be executed on a swarm manager node.

Remove one or more stacks

1つ以上のStackを削除する。

$ docker stack rm [stack-name]

services

docker stack services

List the services in the stack The client and daemon API must both be at least 1.25 to use this command. Use the docker version command on the client to check your client and daemon API versions. Lists the services that are running as part of the specified stack.

List the services in the stack

StackのService一覧を表示する。

$ docker stack services [stack-name]

–filter, -f

Taskをフィルタリングして表示する。

ExpressionSupported
id=xxxxSwarm
label=key=valueSwarm / Kubernetes
mode=xxxxSwarm / Kubernetes
name=xxxxKubernetes
service=xxxxKubernetes
$ docker stack services [stack-name] -f label=key=value

–format

出力をフォーマットする。

PlaceholderDescription
.IDService ID
.NameService name
.ModeService mode (replicated, global)
.ReplicasService replicas
.ImageService image
$ docker stack services [stack-name] --format "{{.ID}} {{.Name}}"