Apply rolling updates to a service (original) (raw)
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 7.4.0 container tag. Then you upgrade the service to use the Redis 7.4.1 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 your Redis tag to the swarm and configure the swarm with a 10 second update delay. Note that the following example shows an older Redis tag:
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 ofRUNNING
, 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: - Now you can update the container image for
redis
. The swarm manager applies the update to nodes according to theUpdateConfig
policy:
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 start 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:
The output ofservice inspect
shows if your update paused due to failure:
To restart a paused update rundocker service update <SERVICE-ID>
. For example:
To avoid repeating certain update failures, you may need to reconfigure the service by passing flags todocker service update
. - Run
docker service ps <SERVICE-ID>
to watch the rolling update:
Before Swarm updates all of the tasks, you can see that some are runningredis:7.4.0
while others are runningredis:7.4.1
. The output above shows the state once the rolling updates are done.
Next, you'll learn how to drain a node in the swarm.