Docker Swarm モードのService作成と削除

Swarm を作成した後 、その Swarm にサービスをデプロイできます。
Docker Swarm モードのServiceを作成する
```console
$ docker service create nginx:latest
rod9tgxuzmcx6662ff7lre5yj
overall progress: 1 out of 1 tasks
1/1: running
verify: Service converged
```
Serviceのリストを確認する
```console
$ docker service ls
ID             NAME            MODE         REPLICAS   IMAGE          PORTS
rod9tgxuzmcx   jovial_agnesi   replicated   1/1        nginx:latest
```
Serviceの情報を確認する
```console
$ docker service ps rod9tgxuzmcx
ID             NAME              IMAGE          NODE      DESIRED STATE   CURRENT STATE           ERROR     PORTS
z5mm0kpcahxe   jovial_agnesi.1   nginx:latest   P88074    Running         Running 8 minutes ago
```
imageを確認する
nginxのimageが作成されたこと
```console
$ docker image ls
REPOSITORY    TAG       IMAGE ID       CREATED       SIZE
spring-demo   latest    7b84519e8e07   2 weeks ago   410MB
nginx         <none>    92b11f67642b   4 weeks ago   187MB
mysql         latest    56b21e040954   7 weeks ago   632MB
```
containerを確認する
```console
$ docker container ls -a
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS          PORTS     NAMES
74b4dce5dc97   nginx:latest   "/docker-entrypoint.…"   15 minutes ago   Up 15 minutes   80/tcp    jovial_agnesi.1.z5mm0kpcahxe1tavfqv3g1dqf
```
Swarmのスケール
```console
$ docker service update rod9tgxuzmcx --replicas 3
rod9tgxuzmcx
overall progress: 3 out of 3 tasks
1/3: running
2/3: running
3/3: running
verify: Service converged
```
Serviceのリストを確認する
```console
$ docker service ls
ID             NAME            MODE         REPLICAS   IMAGE          PORTS
rod9tgxuzmcx   jovial_agnesi   replicated   3/3        nginx:latest
```
Serviceの情報を確認する
```console
$ docker service ps rod9tgxuzmcx
ID             NAME              IMAGE          NODE      DESIRED STATE   CURRENT STATE                ERROR     PORTS
z5mm0kpcahxe   jovial_agnesi.1   nginx:latest   P88074    Running         Running 26 minutes ago

v9zo2n7uiksw   jovial_agnesi.2   nginx:latest   P88074    Running         Running about a minute ago

jo1za2qrqfwx   jovial_agnesi.3   nginx:latest   P88074    Running         Running about a minute ago
```
containerを確認する
```console
$ docker container ls -a
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS          PORTS     NAMES
86581d1da27b   nginx:latest   "/docker-entrypoint.…"   3 minutes ago    Up 3 minutes    80/tcp    jovial_agnesi.3.jo1za2qrqfwx4qyp1rhaujp70
4a1b6ebe2615   nginx:latest   "/docker-entrypoint.…"   3 minutes ago    Up 3 minutes    80/tcp    jovial_agnesi.2.v9zo2n7uikswy000xl0rca2p3
74b4dce5dc97   nginx:latest   "/docker-entrypoint.…"   27 minutes ago   Up 27 minutes   80/tcp    jovial_agnesi.1.z5mm0kpcahxe1tavfqv3g1dqf
```
containerを削除して自動スケールを確認する
```console
$ docker container rm -f 86581d1da27b
86581d1da27b
$ docker container ls -a
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS          PORTS     NAMES
37696d82eb57   nginx:latest   "/docker-entrypoint.…"   4 seconds ago    Created                   jovial_agnesi.3.t9ivr2owoy7co5r3epjm2zgxo
4a1b6ebe2615   nginx:latest   "/docker-entrypoint.…"   19 minutes ago   Up 19 minutes   80/tcp    jovial_agnesi.2.v9zo2n7uikswy000xl0rca2p3
74b4dce5dc97   nginx:latest   "/docker-entrypoint.…"   44 minutes ago   Up 44 minutes   80/tcp    jovial_agnesi.1.z5mm0kpcahxe1tavfqv3g1dqf
```
Serviceにcontainerを自動スケールで作成したことを確認する
```console
$ docker service ls
ID             NAME            MODE         REPLICAS   IMAGE          PORTS
rod9tgxuzmcx   jovial_agnesi   replicated   3/3        nginx:latest
$ docker service ps rod9tgxuzmcx
ID             NAME                  IMAGE          NODE      DESIRED STATE   CURRENT STATE            ERROR
                       PORTS
z5mm0kpcahxe   jovial_agnesi.1       nginx:latest   P88074    Running         Running 47 minutes ago

v9zo2n7uiksw   jovial_agnesi.2       nginx:latest   P88074    Running         Running 22 minutes ago

t9ivr2owoy7c   jovial_agnesi.3       nginx:latest   P88074    Running         Running 2 minutes ago

jo1za2qrqfwx    \_ jovial_agnesi.3   nginx:latest   P88074    Shutdown        Failed 2 minutes ago     "task: non-zero exit (137)"
```
Serviceを完全削除する
```console
~$ docker service rm rod9tgxuzmcx
rod9tgxuzmcx
$ docker service ps rod9tgxuzmcx
no such service: rod9tgxuzmcx
$ docker container ls -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
```