Signed-off-by: Charles Smith <charles.smith@docker.com> Upstream-commit: 68a9224bd42437e63972dc9c3374c065872363b3 Component: engine
3.9 KiB
Apply rolling updates to a service
In a previous step of the tutorial, you scaled the number of instances of a service. In this part of the tutorial, you deploy a service based on the Redis 3.0.6 container image. Then you upgrade the service to use the Redis 3.0.7 container image using rolling updates.
-
If you haven't already, open a terminal and ssh into the machine where you run your manager node. For example, the tutorial uses a machine named
manager1. -
Deploy Redis 3.0.6 to the swarm and configure the swarm with a 10 second update delay:
$ docker service create \ --replicas 3 \ --name redis \ --update-delay 10s \ --update-parallelism 1 \ redis:3.0.6 0u6a4s31ybk7yw2wyvtikmu50You configure the rolling update policy at service deployment time.
The
--update-parallelismflag configures the number of service tasks that the scheduler can update simultaneously. When updates to individual tasks return a state ofRUNNINGorFAILED, the scheduler schedules another task to update until all tasks are updated.The
--update-delayflag configures the time delay between updates to a service task or sets of tasks.You can describe the time
Tas a combination of the number of secondsTs, minutesTm, or hoursTh. So10m30sindicates a 10 minute 30 second delay. -
Inspect the
redisservice:$ docker service inspect --pretty redis ID: 0u6a4s31ybk7yw2wyvtikmu50 Name: redis Mode: Replicated Replicas: 3 Placement: Strategy: Spread UpdateConfig: Parallelism: 1 Delay: 10s ContainerSpec: Image: redis:3.0.6 Resources: -
Now you can update the container image for
redis. The swarm manager applies the update to nodes according to theUpdateConfigpolicy:$ docker service update --image redis:3.0.7 redis redisThe scheduler applies rolling updates as follows:
- Stop the initial number of tasks according to
--update-parallelism. - Schedule updates for the stopped tasks.
- Start the containers for the updated tasks.
- After an update to a task completes, wait for the specified delay period before stopping the next task.
- Stop the initial number of tasks according to
-
Run
docker service inspect --pretty redisto see the new image in the desired state:$ docker service inspect --pretty redis ID: 0u6a4s31ybk7yw2wyvtikmu50 Name: redis Mode: Replicated Replicas: 3 Placement: Strategy: Spread UpdateConfig: Parallelism: 1 Delay: 10s ContainerSpec: Image: redis:3.0.7 Resources: -
Run
docker service tasks <TASK-ID>to watch the rolling update:$ docker service tasks redis ID NAME SERVICE IMAGE LAST STATE DESIRED STATE NODE dos1zffgeofhagnve8w864fco redis.1 redis redis:3.0.7 Running 37 seconds Running worker1 9l3i4j85517skba5o7tn5m8g0 redis.2 redis redis:3.0.7 Running About a minute Running worker2 egiuiqpzrdbxks3wxgn8qib1g redis.3 redis redis:3.0.7 Running 48 seconds Running worker1Before Swarm updates all of the tasks, you can see that some are running
redis:3.0.6while others are runningredis:3.0.7. The output above shows the state once the rolling updates are done.
Next, learn about how to drain a node in the Swarm.