github.com/sld880311/docker@v0.0.0-20200524143708-d5593973a475/docs/reference/commandline/update.md (about)

     1  ---
     2  title: "update"
     3  description: "The update command description and usage"
     4  keywords: "resources, update, dynamically"
     5  ---
     6  
     7  <!-- This file is maintained within the docker/docker Github
     8       repository at https://github.com/docker/docker/. Make all
     9       pull requests against that repo. If you see this file in
    10       another repository, consider it read-only there, as it will
    11       periodically be overwritten by the definitive file. Pull
    12       requests which include edits to this file in other repositories
    13       will be rejected.
    14  -->
    15  
    16  ## update
    17  
    18  ```markdown
    19  Usage:  docker update [OPTIONS] CONTAINER [CONTAINER...]
    20  
    21  Update configuration of one or more containers
    22  
    23  Options:
    24        --blkio-weight value          Block IO (relative weight), between 10 and 1000
    25        --cpu-period int              Limit CPU CFS (Completely Fair Scheduler) period
    26        --cpu-quota int               Limit CPU CFS (Completely Fair Scheduler) quota
    27    -c, --cpu-shares int              CPU shares (relative weight)
    28        --cpu-rt-period int           Limit the CPU real-time period in microseconds
    29        --cpu-rt-runtime int          Limit the CPU real-time runtime in microseconds
    30        --cpuset-cpus string          CPUs in which to allow execution (0-3, 0,1)
    31        --cpuset-mems string          MEMs in which to allow execution (0-3, 0,1)
    32        --help                        Print usage
    33        --kernel-memory string        Kernel memory limit
    34    -m, --memory string               Memory limit
    35        --memory-reservation string   Memory soft limit
    36        --memory-swap string          Swap limit equal to memory plus swap: '-1' to enable unlimited swap
    37        --restart string              Restart policy to apply when a container exits
    38  ```
    39  
    40  ## Description
    41  
    42  The `docker update` command dynamically updates container configuration.
    43  You can use this command to prevent containers from consuming too many
    44  resources from their Docker host.  With a single command, you can place
    45  limits on a single container or on many. To specify more than one container,
    46  provide space-separated list of container names or IDs.
    47  
    48  With the exception of the `--kernel-memory` option, you can specify these
    49  options on a running or a stopped container. On kernel version older than
    50  4.6, you can only update `--kernel-memory` on a stopped container or on
    51  a running container with kernel memory initialized.
    52  
    53  ## Examples
    54  
    55  The following sections illustrate ways to use this command.
    56  
    57  ### Update a container's cpu-shares
    58  
    59  To limit a container's cpu-shares to 512, first identify the container
    60  name or ID. You can use `docker ps` to find these values. You can also
    61  use the ID returned from the `docker run` command.  Then, do the following:
    62  
    63  ```bash
    64  $ docker update --cpu-shares 512 abebf7571666
    65  ```
    66  
    67  ### Update a container with cpu-shares and memory
    68  
    69  To update multiple resource configurations for multiple containers:
    70  
    71  ```bash
    72  $ docker update --cpu-shares 512 -m 300M abebf7571666 hopeful_morse
    73  ```
    74  
    75  ### Update a container's kernel memory constraints
    76  
    77  You can update a container's kernel memory limit using the `--kernel-memory`
    78  option. On kernel version older than 4.6, this option can be updated on a
    79  running container only if the container was started with `--kernel-memory`.
    80  If the container was started *without* `--kernel-memory` you need to stop
    81  the container before updating kernel memory.
    82  
    83  For example, if you started a container with this command:
    84  
    85  ```bash
    86  $ docker run -dit --name test --kernel-memory 50M ubuntu bash
    87  ```
    88  
    89  You can update kernel memory while the container is running:
    90  
    91  ```bash
    92  $ docker update --kernel-memory 80M test
    93  ```
    94  
    95  If you started a container *without* kernel memory initialized:
    96  
    97  ```bash
    98  $ docker run -dit --name test2 --memory 300M ubuntu bash
    99  ```
   100  
   101  Update kernel memory of running container `test2` will fail. You need to stop
   102  the container before updating the `--kernel-memory` setting. The next time you
   103  start it, the container uses the new value.
   104  
   105  Kernel version newer than (include) 4.6 does not have this limitation, you
   106  can use `--kernel-memory` the same way as other options.
   107  
   108  ### Update a container's restart policy
   109  
   110  You can change a container's restart policy on a running container. The new
   111  restart policy takes effect instantly after you run `docker update` on a
   112  container.
   113  
   114  To update restart policy for one or more containers:
   115  
   116  ```bash
   117  $ docker update --restart=on-failure:3 abebf7571666 hopeful_morse
   118  ```
   119  
   120  Note that if the container is started with "--rm" flag, you cannot update the restart
   121  policy for it. The `AutoRemove` and `RestartPolicy` are mutually exclusive for the
   122  container.