$ sudo docker ps | grep sample_roundrobin 867c7a1d1302 127.0.0.1:5000/sample_roundrobin:1.1 "docker-php-entrypoi…" 8 minutes ago Up 7 minutes 80/tcp my_stack_php_myphp.1.p59cbnzoms1a1xdhuxiim4c9k c506b0e6ced4 127.0.0.1:5000/sample_roundrobin:1.1 "docker-php-entrypoi…" 18 minutes ago Up 17 minutes 80/tcp my_stack_php_myphp.3.y4o5doms7gel53dtlpfvzbzq5 f3469c3b37ec 127.0.0.1:5000/sample_roundrobin:1.1 "docker-php-entrypoi…" 18 minutes ago Up 18 minutes 80/tcp my_stack_php_myphp.2.qwk3l05bvs044eb3j7tun4zc8
$ sudo docker stack services my_stack_php ID NAME MODE REPLICAS IMAGE PORTS az6rydt95w73 my_stack_php_myphp replicated 3/3 127.0.0.1:5000/sample_roundrobin:1.1 *:8090->80/tcp
レプリカ数を増やす
レプリカ数を 3 から 4 に変更する。
1 2 3 4 5
$ vi docker-compose.yml ... replicas: 4 ... `
デプロイを行う
1 2 3 4 5 6
$ sudo docker stack deploy -c docker-compose.yml my_stack_php Updating service my_stack_php_myphp (id: az6rydt95w73xwfpr26iuhwcx) image 127.0.0.1:5000/sample_roundrobin:1.1 could not be accessed on a registry to record its digest. Each node will access 127.0.0.1:5000/sample_roundrobin:1.1 independently, possibly leading to different nodes running different versions of the image.
状態を確認する
レプリカ数が 4 になっていることを確認する。
1 2 3
$ sudo docker stack services my_stack_php ID NAME MODE REPLICAS IMAGE PORTS az6rydt95w73 my_stack_php_myphp replicated 4/4 127.0.0.1:5000/sample_roundrobin:1.1 *:8090->80/tcp
新しい4番目の Docker コンテナが起動していることを確認する。
1 2 3 4 5
$ sudo docker ps | grep sample_roundrobin 13fbfb4f00e5 127.0.0.1:5000/sample_roundrobin:1.1 "docker-php-entrypoi…" 30 seconds ago Up 25 seconds 80/tcp my_stack_php_myphp.4.pz884r1h0y80u51s2itwynezj 867c7a1d1302 127.0.0.1:5000/sample_roundrobin:1.1 "docker-php-entrypoi…" 10 minutes ago Up 10 minutes 80/tcp my_stack_php_myphp.1.p59cbnzoms1a1xdhuxiim4c9k c506b0e6ced4 127.0.0.1:5000/sample_roundrobin:1.1 "docker-php-entrypoi…" 20 minutes ago Up 19 minutes 80/tcp my_stack_php_myphp.3.y4o5doms7gel53dtlpfvzbzq5 f3469c3b37ec 127.0.0.1:5000/sample_roundrobin:1.1 "docker-php-entrypoi…" 20 minutes ago Up 20 minutes 80/tcp my_stack_php_myphp.2.qwk3l05bvs044eb3j7tun4zc8
$ sudo docker stack services my_stack_php ID NAME MODE REPLICAS IMAGE PORTS az6rydt95w73 my_stack_php_myphp replicated 4/4 127.0.0.1:5000/sample_roundrobin:1.1 *:8090->80/tcp
Dokcer コンテナも4つ起動している。
1 2 3 4 5
$ sudo docker ps | grep sample_roundrobin 13fbfb4f00e5 127.0.0.1:5000/sample_roundrobin:1.1 "docker-php-entrypoi…" 4 minutes ago Up 3 minutes 80/tcp my_stack_php_myphp.4.pz884r1h0y80u51s2itwynezj 867c7a1d1302 127.0.0.1:5000/sample_roundrobin:1.1 "docker-php-entrypoi…" 13 minutes ago Up 13 minutes 80/tcp my_stack_php_myphp.1.p59cbnzoms1a1xdhuxiim4c9k c506b0e6ced4 127.0.0.1:5000/sample_roundrobin:1.1 "docker-php-entrypoi…" 23 minutes ago Up 23 minutes 80/tcp my_stack_php_myphp.3.y4o5doms7gel53dtlpfvzbzq5 f3469c3b37ec 127.0.0.1:5000/sample_roundrobin:1.1 "docker-php-entrypoi…" 23 minutes ago Up 23 minutes 80/tcp my_stack_php_myphp.2.qwk3l05bvs044eb3j7tun4zc8
レプリカ数を減らす
レプリカ数を 4 から 3 に変更する。
1 2 3 4
$ vi docker-compose.yml ... replicas: 3 ...
デプロイを行う
1 2 3 4 5 6
$ sudo docker stack deploy -c docker-compose.yml my_stack_php Updating service my_stack_php_myphp (id: az6rydt95w73xwfpr26iuhwcx) image 127.0.0.1:5000/sample_roundrobin:1.1 could not be accessed on a registry to record its digest. Each node will access 127.0.0.1:5000/sample_roundrobin:1.1 independently, possibly leading to different nodes running different versions of the image.
状態を確認する
デプロイ直後は、レプリカ数よりも起動している Docker コンテナの数が多い状態になる。
1 2 3
$ sudo docker stack services my_stack_php ID NAME MODE REPLICAS IMAGE PORTS az6rydt95w73 my_stack_php_myphp replicated 4/3 127.0.0.1:5000/sample_roundrobin:1.1 *:8090->80/tcp