What if you could update your app without anyone noticing a thing?
Why Rolling updates in Docker? - Purpose & Use Cases
Imagine you have a website running on a server. To update it, you stop the server, replace the files, and start it again. During this time, visitors see an error or a blank page.
This manual update causes downtime. Visitors get frustrated because the site is unavailable. Also, if something goes wrong, you must fix it quickly or the site stays broken. Doing this repeatedly is slow and risky.
Rolling updates let you update parts of your system one by one without stopping everything. This way, some parts keep working while others update, so users don't notice any downtime.
docker stop myapp replace files docker start myapp
docker service update --image newimage myapp
Rolling updates make it possible to improve your app without interrupting users, keeping your service smooth and reliable.
A popular online store updates its product page code. Using rolling updates, customers keep shopping without any interruptions or errors during the update.
Manual updates cause downtime and risk errors.
Rolling updates update parts gradually to avoid downtime.
This keeps services available and users happy during changes.
Practice
rolling update in Docker?Solution
Step 1: Understand rolling update concept
A rolling update means updating parts of a system bit by bit instead of all at once.Step 2: Apply to Docker containers
In Docker, rolling updates replace containers one by one to avoid downtime.Final Answer:
To update containers gradually without downtime -> Option DQuick Check:
Rolling update = gradual update without downtime [OK]
- Thinking rolling update deletes all containers simultaneously
- Confusing rolling update with backup process
- Assuming rolling update restarts Docker daemon
Solution
Step 1: Identify rolling update options
Docker uses--update-parallelismto control how many containers update at once.Step 2: Match option to rolling update
This option allows gradual updates, which is the essence of rolling updates.Final Answer:
docker service update --update-parallelism -> Option CQuick Check:
Rolling update option = --update-parallelism [OK]
- Using --force which restarts all containers immediately
- Assuming --rollback triggers rolling update
- Inventing a non-existent --rolling-update flag
docker service update --image myapp:v2 --update-parallelism 2 myservice
What will happen during this update?
Solution
Step 1: Understand --update-parallelism effect
The option--update-parallelism 2means update 2 containers at once.Step 2: Apply to service update
Docker updates 2 containers to image v2, then moves to next 2, until all are updated.Final Answer:
Two containers update at a time to v2 until all are updated -> Option BQuick Check:
--update-parallelism 2 means update 2 containers at once [OK]
- Thinking all containers update simultaneously
- Believing only two containers update permanently
- Confusing update with rollback
docker service update --image myapp:v3 --update-parallelism 3 --update-delay 10s myservice
But the update fails and leaves some containers on old version. What is a likely cause?
Solution
Step 1: Check update-delay and parallelism validity
Both--update-delayand--update-parallelismare valid options and can be used together.Step 2: Consider image availability
If the new imagemyapp:v3is missing or invalid, update fails and some containers remain old.Final Answer:
The image myapp:v3 does not exist or is invalid -> Option AQuick Check:
Update fails if new image is missing or bad [OK]
- Assuming update-delay causes failure
- Thinking parallelism must be 1
- Believing update-delay is unsupported
Solution
Step 1: Match update-parallelism to batch size
To update 3 containers at a time, use--update-parallelism 3.Step 2: Set delay between batches
To wait 5 seconds between batches, use--update-delay 5s.Step 3: Verify full command
Combining these with the image and service name gives the correct command.Final Answer:
docker service update --image myapp:v2 --update-parallelism 3 --update-delay 5s myservice -> Option AQuick Check:
Parallelism 3 + delay 5s = correct rolling update command [OK]
- Using wrong parallelism number
- Omitting update-parallelism option
- Setting delay but not parallelism
Ready to prove it?
Pass the test and this pattern moves unknown
