Docker Swarm モードで動作中のサービスについて調べる方法です。
尚、Swarm の管理に関するコマンドは、manager ノード上でのみ実行可能です。
サービスの一覧を調べる
docker service ls
で取得できます。
$ docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
sgwdtal1gqc7 helloworld replicated 1/1 alpine:latest
サービスの詳細を調べる
docker service inspect <サービスID or NAME>
で調べられます。
しかし、このままだと出力が JSON 形式で見づらいので、--pretty
を付けて見やすくしたほうが良いです。
$ docker service inspect helloworld --pretty
ID: sgwdtal1gqc7j0ht0pgl6ehh6
Name: helloworld
Service Mode: Replicated
Replicas: 1
Placement:
UpdateConfig:
Parallelism: 1
On failure: pause
Monitoring Period: 5s
Max failure ratio: 0
Update order: stop-first
RollbackConfig:
Parallelism: 1
On failure: pause
Monitoring Period: 5s
Max failure ratio: 0
Rollback order: stop-first
ContainerSpec:
Image: alpine:latest@sha256:4edbd2beb5f78b1014028f4fbb99f3237d9561100b6881aabbf5acce2c4f9454
Args: ping 192.168.4.1
Init: false
Resources:
Endpoint Mode: vip
サービスがどのノードで動作しているか調べる
docker service ps <サービスID or NAME>
で調べられます。
$ docker service ps helloworld
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
aeg3t0tj1emt helloworld.1 alpine:latest manager1 Running Running about a minute ago
例えば、1つのサービスが2つのノード上で5タスク動作している場合は以下のような出力になります。
$ docker service ps helloworld
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
aeg3t0tj1emt helloworld.1 alpine:latest manager1 Running Running 13 minutes ago
rmf7xhyljero helloworld.2 alpine:latest worker1 Running Running 10 minutes ago
yfezzc46q7ua helloworld.3 alpine:latest worker1 Running Running 10 minutes ago
c3kc1qowfj72 helloworld.4 alpine:latest worker1 Running Running 10 minutes ago
wudt0zzznt1d helloworld.5 alpine:latest manager1 Running Running 9 minutes ago
helloworld
というサービスが5つ動作しており、それが2つのノードに均等に割り振られているのが確認できます。