github.com/vieux/docker@v0.6.3-0.20161004191708-e097c2a938c7/docs/swarm/swarm-tutorial/rolling-update.md (about) 1 <!--[metadata]> 2 +++ 3 title = "Apply rolling updates" 4 description = "Apply rolling updates to a service on the swarm" 5 keywords = ["tutorial, cluster management, swarm, service, rolling-update"] 6 [menu.main] 7 identifier="swarm-tutorial-rolling-update" 8 parent="swarm-tutorial" 9 weight=20 10 +++ 11 <![end-metadata]--> 12 13 # Apply rolling updates to a service 14 15 In a previous step of the tutorial, you [scaled](scale-service.md) the number of 16 instances of a service. In this part of the tutorial, you deploy a service based 17 on the Redis 3.0.6 container image. Then you upgrade the service to use the 18 Redis 3.0.7 container image using rolling updates. 19 20 1. If you haven't already, open a terminal and ssh into the machine where you 21 run your manager node. For example, the tutorial uses a machine named 22 `manager1`. 23 24 2. Deploy Redis 3.0.6 to the swarm and configure the swarm with a 10 second 25 update delay: 26 27 ```bash 28 $ docker service create \ 29 --replicas 3 \ 30 --name redis \ 31 --update-delay 10s \ 32 redis:3.0.6 33 34 0u6a4s31ybk7yw2wyvtikmu50 35 ``` 36 37 You configure the rolling update policy at service deployment time. 38 39 The `--update-delay` flag configures the time delay between updates to a 40 service task or sets of tasks. You can describe the time `T` as a 41 combination of the number of seconds `Ts`, minutes `Tm`, or hours `Th`. So 42 `10m30s` indicates a 10 minute 30 second delay. 43 44 By default the scheduler updates 1 task at a time. You can pass the 45 `--update-parallelism` flag to configure the maximum number of service tasks 46 that the scheduler updates simultaneously. 47 48 By default, when an update to an individual task returns a state of 49 `RUNNING`, the scheduler schedules another task to update until all tasks 50 are updated. If, at any time during an update a task returns `FAILED`, the 51 scheduler pauses the update. You can control the behavior using the 52 `--update-failure-action` flag for `docker service create` or 53 `docker service update`. 54 55 3. Inspect the `redis` service: 56 57 ```bash 58 $ docker service inspect --pretty redis 59 60 ID: 0u6a4s31ybk7yw2wyvtikmu50 61 Name: redis 62 Service Mode: Replicated 63 Replicas: 3 64 Placement: 65 Strategy: Spread 66 UpdateConfig: 67 Parallelism: 1 68 Delay: 10s 69 ContainerSpec: 70 Image: redis:3.0.6 71 Resources: 72 Endpoint Mode: vip 73 ``` 74 75 4. Now you can update the container image for `redis`. The swarm manager 76 applies the update to nodes according to the `UpdateConfig` policy: 77 78 ```bash 79 $ docker service update --image redis:3.0.7 redis 80 redis 81 ``` 82 83 The scheduler applies rolling updates as follows by default: 84 85 * Stop the first task. 86 * Schedule update for the stopped task. 87 * Start the container for the updated task. 88 * If the update to a task returns `RUNNING`, wait for the 89 specified delay period then stop the next task. 90 * If, at any time during the update, a task returns `FAILED`, pause the 91 update. 92 93 5. Run `docker service inspect --pretty redis` to see the new image in the 94 desired state: 95 96 ```bash 97 $ docker service inspect --pretty redis 98 99 ID: 0u6a4s31ybk7yw2wyvtikmu50 100 Name: redis 101 Service Mode: Replicated 102 Replicas: 3 103 Placement: 104 Strategy: Spread 105 UpdateConfig: 106 Parallelism: 1 107 Delay: 10s 108 ContainerSpec: 109 Image: redis:3.0.7 110 Resources: 111 Endpoint Mode: vip 112 ``` 113 114 The output of `service inspect` shows if your update paused due to failure: 115 116 ```bash 117 $ docker service inspect --pretty redis 118 119 ID: 0u6a4s31ybk7yw2wyvtikmu50 120 Name: redis 121 ...snip... 122 Update status: 123 State: paused 124 Started: 11 seconds ago 125 Message: update paused due to failure or early termination of task 9p7ith557h8ndf0ui9s0q951b 126 ...snip... 127 ``` 128 129 To restart a paused update run `docker service update <SERVICE-ID>`. For example: 130 131 ```bash 132 docker service update redis 133 ``` 134 135 To avoid repeating certain update failures, you may need to reconfigure the 136 service by passing flags to `docker service update`. 137 138 6. Run `docker service ps <SERVICE-ID>` to watch the rolling update: 139 140 ```bash 141 $ docker service ps redis 142 143 NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR 144 redis.1.dos1zffgeofhagnve8w864fco redis:3.0.7 worker1 Running Running 37 seconds 145 \_ redis.1.88rdo6pa52ki8oqx6dogf04fh redis:3.0.6 worker2 Shutdown Shutdown 56 seconds ago 146 redis.2.9l3i4j85517skba5o7tn5m8g0 redis:3.0.7 worker2 Running Running About a minute 147 \_ redis.2.66k185wilg8ele7ntu8f6nj6i redis:3.0.6 worker1 Shutdown Shutdown 2 minutes ago 148 redis.3.egiuiqpzrdbxks3wxgn8qib1g redis:3.0.7 worker1 Running Running 48 seconds 149 \_ redis.3.ctzktfddb2tepkr45qcmqln04 redis:3.0.6 mmanager1 Shutdown Shutdown 2 minutes ago 150 ``` 151 152 Before Swarm updates all of the tasks, you can see that some are running 153 `redis:3.0.6` while others are running `redis:3.0.7`. The output above shows 154 the state once the rolling updates are done. 155 156 Next, learn about how to [drain a node](drain-node.md) in the swarm.