Practical Exercises for Docker Compose: Part 5

Deploy: update_config: parallelism

nano docker-compose.ymlversion: "3.7"
services:
alpine:
image: alpine:3.8
command: sleep 600
deploy:
replicas: 6
update_config:
parallelism: 1
docker stack rm mystack
docker stack deploy -c docker-compose.yml mystack
docker ps -a
docker stack deploy -c docker-compose.yml  mystack
2018-11-08T12:48:34.385699607+02:00 service update qdzqiek7c59mkxznatszsh13j (name=mystack_alpine)
2018-11-08T12:48:37.423780596+02:00 service update qdzqiek7c59mkxznatszsh13j (name=mystack_alpine)
2018-11-08T12:48:39.804717121+02:00 service update qdzqiek7c59mkxznatszsh13j (name=mystack_alpine)
docker stack deploy -c docker-compose.yml  mystack
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                       PORTS               NAMES
bafa8e4e1d62 alpine:3.8 "sleep 6001" 21 seconds ago Up 4 seconds mystack_alpine.5.mtw5rzfpyd6dwnh9mez7p7hlk
a80b531eff59 alpine:3.8 "sleep 6001" 21 seconds ago Up 4 seconds mystack_alpine.6.nl9culv3otymevgjufamkkwld
fa45c52b0825 alpine:3.8 "sleep 6001" 21 seconds ago Up 4 seconds mystack_alpine.1.oe2d85c55uf1qlbvv1pozcsgx
2565cfbda1db alpine:3.8 "sleep 6001" 21 seconds ago Up 5 seconds mystack_alpine.4.5zaqrvwv32ou8vmdvnbu21qtn
b69ceeaf69a1 alpine:3.8 "sleep 6001" 21 seconds ago Up 5 seconds mystack_alpine.2.utc38k1pg124zx65ae1s8qo5g
9669904d0bb1 alpine:3.8 "sleep 6001" 21 seconds ago Up 4 seconds mystack_alpine.3.zbltrdwmk0omxtkywuwhlw9ub
dc8566cc12ae alpine:3.8 "sleep 600" 9 minutes ago Exited (137) 8 seconds ago mystack_alpine.3.bi13jj6v7f2s3b31yc6k9dmf0
9d385bfd3565 alpine:3.8 "sleep 600" 9 minutes ago Exited (137) 8 seconds ago mystack_alpine.6.g8w5a0fe0ufcum2y2lhd0i1dq
58f14d78f436 alpine:3.8 "sleep 600" 9 minutes ago Exited (137) 8 seconds ago mystack_alpine.1.zotzhrpqblzzyo62urafwgzcs
2090bb37bb31 alpine:3.8 "sleep 600" 9 minutes ago Exited (137) 8 seconds ago mystack_alpine.2.loezk57p62tkfohgzbh1tc1j8
c8df0b31e188 alpine:3.8 "sleep 600" 9 minutes ago Exited (137) 8 seconds ago mystack_alpine.4.619ms1rkhar35un6x4g5ulc3h
c85a0f2db1e0 alpine:3.8 "sleep 600" 9 minutes ago Exited (137) 8 seconds ago mystack_alpine.5.odw21g73i1p62s90lpj1936xv
docker events  --filter event=create  --filter event=kill
docker stack deploy -c docker-compose.yml  mystack
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS                            PORTS               NAMES
84da4828fea3 alpine:3.8 "sleep 6002" 3 seconds ago Created mystack_alpine.4.ludkp9e9ec63tf27n05j2h8rt
99d63687086c alpine:3.8 "sleep 6002" 18 seconds ago Up 3 seconds mystack_alpine.1.zbfm2q2403wg5f0626dlodab4
5d4ac8f2ae15 alpine:3.8 "sleep 6002" 32 seconds ago Up 17 seconds mystack_alpine.5.oadzbajbcr6l1rms28kb23xux
350971f0734e alpine:3.8 "sleep 6002" 47 seconds ago Up 32 seconds mystack_alpine.2.lxggijot4518tj0xl3bi36eay
95f6fcc3c898 alpine:3.8 "sleep 6002" About a minute ago Up 46 seconds mystack_alpine.6.qgje7g5r7e7e24neuqiafip0g
960174cdab88 alpine:3.8 "sleep 6002" About a minute ago Up About a minute mystack_alpine.3.v9zm2yipmvjzb673da8sbryh1
nano docker-compose.yml
docker stack deploy -c docker-compose.yml  mystack

Deploy: update_config: failure_ratio and failure_action

failure_ratio specifies which percent failure to tolerate: Syntax: 0.1 means 10 percent.failure_action: Specifies what to do if an update fails. continue, rollback, or pause (default: pause).
nano docker-compose.ymlversion: "3.7"
services:
alpine:
image: alpine:3.8
command: exit 1
deploy:
replicas: 6
update_config: parallelism: 1
max_failure_ratio: 0
failure_action: pause
docker stack deploy -c docker-compose.yml  mystack
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
cbcaf8fce479 alpine:3.8 "exit 1" 6 seconds ago Created mystack_alpine.2.zvk1x6hevpt3x0q6aha0616sx
3ce0f3bca6c8 alpine:3.8 "exit 1" 12 seconds ago Created mystack_alpine.2.hyikxli7cwuk0xauaqw87epu0
4ae02b292f54 alpine:3.8 "exit 1" 18 seconds ago Created mystack_alpine.2.lseuovn0g4imn75q1eufnyfx9
1ea70f30f397 alpine:3.8 "exit 1" 24 seconds ago Created mystack_alpine.2.tfwagwvevh9vdxyne7cfy41fa
2eeef13d4240 alpine:3.8 "exit 1" 30 seconds ago Created mystack_alpine.2.n5qny1d5sbwah7fgsa83eabat
b926e22199d1 alpine:3.8 "sleep 6003" 21 minutes ago Up 20 minutes mystack_alpine.5.w3ll2y30r1b75137fbbqak1rf
248f8ffe019e alpine:3.8 "sleep 6003" 21 minutes ago Up 20 minutes mystack_alpine.1.62dpe6cgrtmkercmn2bdlo3j3
815143b43f11 alpine:3.8 "sleep 6003" 21 minutes ago Up 21 minutes mystack_alpine.4.enk3mweaht4zqre0jehm2nyn1
c13461b6f58c alpine:3.8 "sleep 6003" 21 minutes ago Up 21 minutes mystack_alpine.3.9jfg8kc1l0ps6km6hv5wlzddc
f2dc173cbf21 alpine:3.8 "sleep 6003" 21 minutes ago Up 21 minutes mystack_alpine.6.8mo8t73z58jbf1e9vhvzjup53
docker stack rm mystack
docker container prune -f
nano docker-compose.ymlversion: "3.7"
services:
alpine:
image: alpine:3.8
command: sleep 600
deploy:
replicas: 6
docker stack deploy -c docker-compose.yml  mystack
nano docker-compose.ymlversion: "3.7"
services:
alpine:
image: alpine:3.8
command: exit 1
deploy:
replicas: 6
update_config: parallelism: 1
max_failure_ratio: 0
failure_action: rollback
docker stack deploy -c docker-compose.yml  mystack
docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                        PORTS               NAMES
c2d1ae806906 alpine:3.8 "sleep 600" 25 seconds ago Up 22 seconds mystack_alpine.2.soht49wefpwm1nvm1gbl7ru1l
455a5907758a alpine:3.8 "exit 1" 40 seconds ago Created mystack_alpine.2.yr0zkfu9n40s0rbezfhjtl6yu
3c254ba9a72b alpine:3.8 "sleep 600" 2 minutes ago Exited (137) 26 seconds ago mystack_alpine.2.04g1vrnoomagvv89aobbbzmxz
b635a1e52147 alpine:3.8 "sleep 600" 2 minutes ago Up 2 minutes mystack_alpine.1.gibfdph75s0o46s5h3x96csm2
0ac32ac0ad34 alpine:3.8 "sleep 600" 2 minutes ago Up 2 minutes mystack_alpine.3.oxs3mjm7vp3c6jbc1kj2kz990
33554d287fe9 alpine:3.8 "sleep 600" 2 minutes ago Up 2 minutes mystack_alpine.5.ds3lra1qvr9y8e8b1xi2cn5c0
f381b1250167 alpine:3.8 "sleep 600" 2 minutes ago Up 2 minutes mystack_alpine.4.t4gv1gor6aul3b53ei6pcxu5e
fd97395ba2ac alpine:3.8 "sleep 600" 2 minutes ago Up 2 minutes mystack_alpine.6.n1nshrlnywqcrvn5u2x93nr10
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
455a5907758a alpine:3.8 "exit 1" 7 seconds ago Created mystack_alpine.2.yr0zkfu9n40s0rbezfhjtl6yu
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS                       PORTS               NAMES
3c254ba9a72b alpine:3.8 "sleep 600" About a minute ago Exited (137)
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                        PORTS               NAMES
c2d1ae806906 alpine:3.8 "sleep 600" 25 seconds ago Up 22 seconds mystack_alpine.2.soht49wefpwm1nvm1gbl7ru1l
update_config:        parallelism: 1
max_failure_ratio: 0
failure_action: rollback

Deploy: update_config: monitor

monitor: Duration after each task update to monitor for failure (ns|us|ms|s|m|h) (default 0s).

Parallelism Experiments Output

cut -c1-60 /tmp/events | egrep 'create|kill'
2018-11-03T10:01:35.148583578+02:00 container create 8b51499
2018-11-03T10:01:37.840231366+02:00 container kill be8f3715a
2018-11-03T10:01:37.865611953+02:00 container kill be8f3715a
2018-11-03T10:01:39.886188372+02:00 container create a38781a
2018-11-03T10:01:42.572866743+02:00 container kill e498e5f5f
2018-11-03T10:01:42.598606635+02:00 container kill e498e5f5f
2018-11-03T10:01:44.423905486+02:00 container create 64ae4c0
2018-11-03T10:01:47.123993008+02:00 container kill 914343611
2018-11-03T10:01:47.146988704+02:00 container kill 914343611
2018-11-03T10:01:48.972005129+02:00 container create b37cef5
2018-11-03T10:01:51.642712373+02:00 container kill 92619e0a6
2018-11-03T10:01:51.667003244+02:00 container kill 92619e0a6
2018-11-03T10:01:53.497100262+02:00 container create 8a73470
2018-11-03T10:01:56.163374613+02:00 container kill 420dc4d89
2018-11-03T10:01:56.188237090+02:00 container kill 420dc4d89
2018-11-03T10:01:58.000843644+02:00 container create 41b4480
2018-11-03T10:02:00.699576981+02:00 container kill c8f4d973c
2018-11-03T10:02:00.721565297+02:00 container kill c8f4d973
cut -c1-60 /tmp/events | egrep 'create|kill'
2018-11-03T10:08:47.299682233+02:00 container create 6f1df52
2018-11-03T10:08:47.567222566+02:00 container create ea9bf95
2018-11-03T10:08:49.943237084+02:00 container kill 8b51499ad
2018-11-03T10:08:49.958679991+02:00 container kill 64ae4c05c
2018-11-03T10:08:49.977677725+02:00 container kill 8b51499ad
2018-11-03T10:08:49.997521920+02:00 container kill 64ae4c05c
2018-11-03T10:08:52.539334772+02:00 container create cdbbef8
2018-11-03T10:08:52.812900162+02:00 container create 16e1af2
2018-11-03T10:08:55.157361545+02:00 container kill b37cef51e
2018-11-03T10:08:55.169221551+02:00 container kill 8a73470b2
2018-11-03T10:08:55.193477357+02:00 container kill b37cef51e
2018-11-03T10:08:55.207277169+02:00 container kill 8a73470b2
2018-11-03T10:08:57.830146930+02:00 container create 0ab17e5
2018-11-03T10:08:57.949710902+02:00 container create 9cc8547
2018-11-03T10:09:00.233887111+02:00 container kill a38781a0f
2018-11-03T10:09:00.257647812+02:00 container kill 41b4480ad
2018-11-03T10:09:00.272834309+02:00 container kill a38781a0f
2018-11-03T10:09:00.288598877+02:00 container kill 41b4480ad
cut -c1-60 /tmp/events | egrep 'create|kill'
2018-11-03T10:11:34.283896923+02:00 container create 8a0373b
2018-11-03T10:11:34.583536405+02:00 container create 61cbe75
2018-11-03T10:11:34.803563295+02:00 container create a2bd707
2018-11-03T10:11:36.854815108+02:00 container kill cdbbef891
2018-11-03T10:11:36.861978752+02:00 container kill 0ab17e57f
2018-11-03T10:11:36.890035520+02:00 container kill ea9bf9502
2018-11-03T10:11:36.899725135+02:00 container kill cdbbef891
2018-11-03T10:11:36.905718703+02:00 container kill 0ab17e57f
2018-11-03T10:11:36.922317316+02:00 container kill ea9bf9502
2018-11-03T10:11:39.891013146+02:00 container create 7576427
2018-11-03T10:11:40.238136177+02:00 container create a26d947
2018-11-03T10:11:40.439589543+02:00 container create 53002e5
2018-11-03T10:11:42.434787914+02:00 container kill 16e1af20f
2018-11-03T10:11:42.445537379+02:00 container kill 9cc854731
2018-11-03T10:11:42.485085063+02:00 container kill 9cc854731
2018-11-03T10:11:42.490162686+02:00 container kill 16e1af20f
2018-11-03T10:11:42.498272764+02:00 container kill 6f1df5233
2018-11-03T10:11:42.547462663+02:00 container kill 6f1df523
cut -c1-60 /tmp/events | egrep 'create|kill'
2018-11-03T10:13:22.444286947+02:00 container create bb4b2db
2018-11-03T10:13:22.838989116+02:00 container create a00d0b1
2018-11-03T10:13:23.039740661+02:00 container create f1f9090
2018-11-03T10:13:23.595395816+02:00 container create 568b219
2018-11-03T10:13:23.824193225+02:00 container create 77d7d22
2018-11-03T10:13:24.191986311+02:00 container create 1ea8ad8
2018-11-03T10:13:25.105183046+02:00 container kill 8a0373b67
2018-11-03T10:13:25.146410226+02:00 container kill 8a0373b67
2018-11-03T10:13:25.150991208+02:00 container kill 53002e5b3
2018-11-03T10:13:25.190384877+02:00 container kill 75764275f
2018-11-03T10:13:25.204178523+02:00 container kill a2bd707bc
2018-11-03T10:13:25.230797581+02:00 container kill a26d9476c
2018-11-03T10:13:25.234104353+02:00 container kill 61cbe7540
2018-11-03T10:13:25.252980697+02:00 container kill 53002e5b3
2018-11-03T10:13:25.268581894+02:00 container kill 75764275f
2018-11-03T10:13:25.283548856+02:00 container kill a2bd707bc
2018-11-03T10:13:25.299920739+02:00 container kill a26d9476c
2018-11-03T10:13:25.306631692+02:00 container kill 61cbe7540

Deploy: restart_policy

nano docker-compose.ymlversion: "3.7"
services:
alpine:
image: alpine:3.8
command: sleep 3
deploy:
replicas: 1
docker stack deploy -c docker-compose.yml mystack
docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
42738b793169 alpine:3.8 "sleep 3" 6 seconds ago Up Less than a second mystack_alpine.1.wopmb7xzyakbftkwsk9eq0goo
95e00ae7c883 alpine:3.8 "sleep 3" 15 seconds ago Exited (0) 7 seconds ago mystack_alpine.1.h0n7hh12bn4jgb35bozpirm9r
bac92d42ca3f alpine:3.8 "sleep 3" 25 seconds ago Exited (0) 16 seconds ago mystack_alpine.1.2xujcjgypj9kbdcwsw0g0ysw8
0998efbcba8f alpine:3.8 "sleep 3" 34 seconds ago Exited (0) 26 seconds ago mystack_alpine.1.puqpmp9u13ivqvclah5cmidgx
nano docker-compose.ymlversion: "3.7"
services:
alpine:
image: alpine:3.8
command: sleep 2.22
deploy:
replicas: 1
restart_policy:
max_attempts: 3
docker stack deploy -c docker-compose.yml  mystack

window: How long to wait before deciding if a restart has succeeded, specified as a duration (default: decide immediately).

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store