Docker update command
docker update The command is used to update the resource limits of a Docker container, including memory, CPU, and so on.
docker updateThe command can dynamically adjust resource limits while a container is running, without stopping and restarting it.
Syntax
docker update [OPTIONS] CONTAINER [CONTAINER...]
Common parameters
CONTAINER: The name or container ID of the container whose resource limits are to be updated. You can specify one or more containers.OPTIONS: Used to specify the resource limits to update.
Common OPTIONS:
1、--memory, -m: Set the container's memory limit.
- Format:
[ ] - For example:
500m、2g, etc.
docker update -m 2g my_container
2、--memory-swap: Set the total limit on the container's memory and swap space. If set to -1, swap space is unlimited.
- Format:
, such as[ ] 2g, or-1means unlimited.
docker update --memory-swap 3g my_container
3、--cpu-shares: Set the container's CPU priority, a relative value. The default is 1024; a larger value indicates a higher priority.
- This option does not directly limit the container's CPU usage; instead, it controls the priority of CPU resource allocation.
docker update --cpu-shares 2048 my_container
4、--cpus: Set the number of CPU cores used by the container. This option can limit the maximum number of CPU cores a container can use.
- Format:
, for example:1.5means using at most 1.5 CPU cores.
docker update --cpus 2 my_container
5、--cpu-period: Set the CPU period. Used together with --cpu-quota to limit the container's CPU usage time. The unit is microseconds (default value:100000 microseconds = 100ms).
docker update --cpu-period 50000 my_container
6、--cpu-quota: Set the maximum CPU time a container can use in each period. The unit is microseconds. It needs to be used with --cpu-period .
docker update --cpu-quota 25000 my_container
7、--blkio-weight: Set the block I/O weight (range:10 to 1000), indicating the container's priority for disk I/O operations. The default value is 500。
docker update --blkio-weight 800 my_container
8、--pids-limit: Set the maximum number of processes the container can use.
- Format:
, for example:100。
docker update --pids-limit 200 my_container
9、--restart: Set the container's restart policy (no、on-failure、always、unless-stopped)。
docker update --restart always my_container
Example
** 1. Update a container's memory limit:**
docker update -m 2g my_container
This command updates the memory limit of my_container to 2GB.
2. Set the CPU core count limit:
docker update --cpus 1.5 my_container
This command limits my_container to using at most 1.5 CPU cores.
** 3. Update a container's CPU weight:**
docker update --cpu-shares 1024 my_container
This command sets the container's CPU weight to 1024, which is the default value.
** 4. Update a container's block I/O weight:**
docker update --blkio-weight 700 my_container
This command sets the container's disk I/O weight to 700; the weight range is 10 to 1000.
Usage limitations
docker updateThe command takes effect immediately but does not affect the applications running inside the container; the container continues running.- Only container resource limits can be adjusted; other container configurations (such as environment variables, port mappings, etc.) cannot be modified.
Docker Command Reference