Service Updates
- Provides rolling replacement of tasks/containers in a service
- Limits downtime (be careful with "prevent" downtime)
- Will replace containers for most changes
- Has many, many cli options to control the update
- Create options will usually change, adding -add or -rm to them
- Includes rollback and healthcheck options
- Also has scale & rollback subcommand for quicker access
docker service scale web=4
anddocker service rollback web
- A stack deploy, when pre-existing, will issue service updates
Update Examples
- Just update the image used to a newer version
docker service update --image myapp:1.2.1 <servicename>
- Adding an environment variable and remove a port
docker service update --env-add NODE_ENV=production --publish-rm 8080
- Change number of replicas of two services
docker service scale web=8 api=6
Updates in Stack Files
- Same command. Just edit the YAML file, then
docker stack deploy -c file.yml <stackname>
Some other examples
[node1] ~> docker service create -p 8088:80 --name web nginx:1.13.7
ptc2b8k6enqrsdoegmga7fgnd
overall progress: 1 out of 1 tasks
1/1: running [==================================================>]
verify: Service converged
[node1] ~> docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
ptc2b8k6enqr web replicated 1/1 nginx:1.13.7 *:8088->80/tcp
[node1] ~> docker service scale web=5
web scaled to 5
overall progress: 5 out of 5 tasks
1/5: running [==================================================>]
2/5: running [==================================================>]
3/5: running [==================================================>]
4/5: running [==================================================>]
5/5: running [==================================================>]
verify: Service converged
[node1] ~> docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
ptc2b8k6enqr web replicated 5/5 nginx:1.13.7 *:8088->80/tcp
[node1] ~> docker service update --image nginx:1.13.6 web
web
overall progress: 5 out of 5 tasks
1/5: running [==================================================>]
2/5: running [==================================================>]
3/5: running [==================================================>]
4/5: running [==================================================>]
5/5: running [==================================================>]
verify: Service converged
[node1] ~> docker service update --publish-rm 8088 --publish-add 9090:80 web
web
overall progress: 5 out of 5 tasks
1/5: running [==================================================>]
2/5: running [==================================================>]
3/5: running [==================================================>]
4/5: running [==================================================>]
5/5: running [==================================================>]
verify: Service converged
[node1] ~> docker service update --force web
docker service update --force web
web
overall progress: 5 out of 5 tasks
1/5: running [==================================================>]
2/5: running [==================================================>]
3/5: running [==================================================>]
4/5: running [==================================================>]
5/5: running [==================================================>]
verify: Service converged
External links
https://docs.docker.com/engine/reference/commandline/service_update/