As per business requirement, we might want to perform rolling updates to our services for configuration changes and new Docker Image versions without any downtime.
In this part of the tutorial, we will deploy a service based on the Redis 3.0.6 container tag. Then we will upgrade the service to use the Redis 3.0.7 container image using rolling updates
- For our demonstration, we will be using centos-07.
- We will be using 3 machines for our lab, 1 machine as a swarm Manager node and 2 swarm worker nodes. These servers have below IP details:
3. The memory should be at least 2 GB and there should be at least 2 core CPUs for each node.
4. You have already configured Docker Swarm. Read my previous article to understand how to configure the docker swarm.
Deploy a service based on the Redis 3.0.6 container tag:
- Run the command below to deploy a redis service with 3 replicas of it with image — “redis:3.0.6” and given the name of this service as “redis”. Notice that we have also passed a flag called “ — update-delay 20s”.
docker service create — replicas 3 — name redis — update-delay 20s redis:3.0.6
--update-delay flag configures the time delay between updates to a service task or sets of tasks.
2. The “docker service ls” command will show that 3 replicas of the container is running.
3. Run the below command to know, on which nodes the container is running:
docker service ps redis
4. If you need more information related to the service, run the below command. Note that “Delay” mentioned as 20s.
docker service inspect — pretty redis
Upgrade the service using Rolling Update
Now Let’s upgrade the service to use the Redis 3.0.7 container image using rolling updates.
8. Now we can update the container image for
redis. We will be upgrading the containers to redis 3.0.7 image. The swarm manager applies the update to nodes according to the
Run the below command for the upgrade:
docker service update — image redis:3.0.7 redis
You will observe the delay of 20 seconds before the swarm Manager starts upgrading the next container.
9. The command “docker service ls” shows that the containers have been upgraded to redis:3.0.7 image.
10. The below command will show that how the rolling upgrade was performed. You will notice that all the upgrades were not happened at once.
This concludes our tutorial for Performing Rolling Upgrade of a Service.