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 \ redis:3.0.6 0u6a4s31ybk7yw2wyvtikmu50
You configure the rolling update policy at service deployment time.
The
--update-delay
flag configures the time delay between updates to a service task or sets of tasks. You can describe the timeT
as a combination of the number of secondsTs
, minutesTm
, or hoursTh
. So10m30s
indicates a 10 minute 30 second delay.By default the scheduler updates 1 task at a time. You can pass the
--update-parallelism
flag to configure the maximum number of service tasks that the scheduler updates simultaneously.By default, when an update to an individual task returns a state of
RUNNING
, the scheduler schedules another task to update until all tasks are updated. If, at any time during an update a task returnsFAILED
, the scheduler pauses the update. You can control the behavior using the--update-failure-action
flag fordocker service create
ordocker service update
. -
Inspect the
redis
service:$ 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 theUpdateConfig
policy:$ docker service update --image redis:3.0.7 redis redis
The scheduler applies rolling updates as follows by default:
- Stop the first task.
- Schedule update for the stopped task.
- Start the container for the updated task.
- If the update to a task returns
RUNNING
, wait for the specified delay period then stop the next task. - If, at any time during the update, a task returns
FAILED
, pause the update.
-
Run
docker service inspect --pretty redis
to 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:
The output of
service inspect
shows if your update paused due to failure:$ docker service inspect --pretty redis ID: 0u6a4s31ybk7yw2wyvtikmu50 Name: redis ...snip... Update status: State: paused Started: 11 seconds ago Message: update paused due to failure or early termination of task 9p7ith557h8ndf0ui9s0q951b ...snip...
To restart a paused update run
docker service update <SERVICE-ID>
. For example:docker service update redis
To avoid repeating certain update failures, you may need to reconfigure the service by passing flags to
docker service update
. -
Run
docker service ps <SERVICE-ID>
to watch the rolling update:$ docker service ps redis ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR dos1zffgeofhagnve8w864fco redis.1 redis:3.0.7 worker1 Running Running 37 seconds 88rdo6pa52ki8oqx6dogf04fh \_ redis.1 redis:3.0.6 worker2 Shutdown Shutdown 56 seconds ago 9l3i4j85517skba5o7tn5m8g0 redis.2 redis:3.0.7 worker2 Running Running About a minute 66k185wilg8ele7ntu8f6nj6i \_ redis.2 redis:3.0.6 worker1 Shutdown Shutdown 2 minutes ago egiuiqpzrdbxks3wxgn8qib1g redis.3 redis:3.0.7 worker1 Running Running 48 seconds ctzktfddb2tepkr45qcmqln04 \_ redis.3 redis:3.0.6 mmanager1 Shutdown Shutdown 2 minutes ago
Before Swarm updates all of the tasks, you can see that some are running
redis:3.0.6
while 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.
© 2017 Docker, Inc.
Licensed under the Apache License, Version 2.0.
Docker and the Docker logo are trademarks or registered trademarks of Docker, Inc. in the United States and/or other countries.
Docker, Inc. and other parties may also have trademark rights in other terms used herein.
https://docs.docker.com/v1.12/engine/swarm/swarm-tutorial/rolling-update/