github.com/portworx/docker@v1.12.1/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      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      ```
    73  
    74  4. Now you can update the container image for `redis`. The swarm  manager
    75  applies the update to nodes according to the `UpdateConfig` policy:
    76  
    77      ```bash
    78      $ docker service update --image redis:3.0.7 redis
    79      redis
    80      ```
    81  
    82      The scheduler applies rolling updates as follows by default:
    83  
    84      * Stop the first task.
    85      * Schedule update for the stopped task.
    86      * Start the container for the updated task.
    87      * If the update to a task returns `RUNNING`, wait for the
    88      specified delay period then stop the next task.
    89      * If, at any time during the update, a task returns `FAILED`, pause the
    90      update.
    91  
    92  5. Run `docker service inspect --pretty redis` to see the new image in the
    93  desired state:
    94  
    95      ```bash
    96      $ docker service inspect --pretty redis
    97  
    98      ID:             0u6a4s31ybk7yw2wyvtikmu50
    99      Name:           redis
   100      Mode:           Replicated
   101       Replicas:      3
   102      Placement:
   103       Strategy:	    Spread
   104      UpdateConfig:
   105       Parallelism:   1
   106       Delay:         10s
   107      ContainerSpec:
   108       Image:         redis:3.0.7
   109      Resources:
   110      ```
   111  
   112      The output of `service inspect` shows if your update paused due to failure:
   113  
   114      ```bash
   115      $ docker service inspect --pretty redis
   116  
   117      ID:             0u6a4s31ybk7yw2wyvtikmu50
   118      Name:           redis
   119      ...snip...
   120      Update status:
   121       State:      paused
   122       Started:    11 seconds ago
   123       Message:    update paused due to failure or early termination of task 9p7ith557h8ndf0ui9s0q951b
   124      ...snip...
   125      ```
   126  
   127      To restart a paused update run `docker service update <SERVICE-ID>`. For example:
   128  
   129      ```bash
   130      docker service update redis
   131      ```
   132  
   133      To avoid repeating certain update failures, you may need to reconfigure the
   134      service by passing flags to `docker service update`.
   135  
   136  6. Run `docker service ps <SERVICE-ID>` to watch the rolling update:
   137  
   138      ```bash
   139      $ docker service ps redis
   140  
   141      ID                         NAME         IMAGE        NODE       DESIRED STATE  CURRENT STATE            ERROR
   142      dos1zffgeofhagnve8w864fco  redis.1      redis:3.0.7  worker1    Running        Running 37 seconds
   143      88rdo6pa52ki8oqx6dogf04fh   \_ redis.1  redis:3.0.6  worker2    Shutdown       Shutdown 56 seconds ago
   144      9l3i4j85517skba5o7tn5m8g0  redis.2      redis:3.0.7  worker2    Running        Running About a minute
   145      66k185wilg8ele7ntu8f6nj6i   \_ redis.2  redis:3.0.6  worker1    Shutdown       Shutdown 2 minutes ago
   146      egiuiqpzrdbxks3wxgn8qib1g  redis.3      redis:3.0.7  worker1    Running        Running 48 seconds
   147      ctzktfddb2tepkr45qcmqln04   \_ redis.3  redis:3.0.6  mmanager1  Shutdown       Shutdown 2 minutes ago
   148      ```
   149  
   150      Before Swarm updates all of the tasks, you can see that some are running
   151      `redis:3.0.6` while others are running `redis:3.0.7`. The output above shows
   152      the state once the rolling updates are done.
   153  
   154  Next, learn about how to [drain a node](drain-node.md) in the swarm.