Docker update command
docker updateThe command is used to update resource limits for Docker containers, including memory, CPU, etc.
docker updateThe command can dynamically adjust resource limits while the container is running, without stopping and restarting the container.
Syntax
docker update [OPTIONS] CONTAINER [CONTAINER...]
Common Parameters
CONTAINER: The container name or container ID whose resource limits are to be updated. You can specify one or more containers.OPTIONSUsed to specify the resource limits that need to be updated.
Common options OPTIONS:
1、--memory, -m: Set the memory limit for the container.
- Format:
<size>[<unit>] - For example:
500m、2getc.
docker update -m 2g my_container
2、--memory-swap: Set the total limit for container memory and swap space. If set to-1, indicating no limit on swap space.
- Format:
<size>[<unit>], such as2g, or-1Indicates unlimited.
docker update --memory-swap 3g my_container
3、--cpu-shares: Set the container's CPU priority, a relative value. The default is1024, a larger value indicates higher priority.
- This option does not directly limit the container's CPU usage, but instead 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 the container can use.
- Format:
<number>, for example:1.5Means it can use up to 1.5 CPU cores.
docker update --cpus 2 my_container
5、--cpu-period: Set the CPU period time. Used in conjunction with--cpu-quotaLimit the container's CPU usage time. The unit is microseconds (default value:100000microsecond = 100ms).
docker update --cpu-period 50000 my_container
6、--cpu-quota: Set the maximum CPU time the container can use per period. The unit is microseconds. It needs to be used with--cpu-periodUsed in combination.
docker update --cpu-quota 25000 my_container
7、--blkio-weight: Set the block I/O weight (range:10to1000), representing the priority of the container's disk I/O operations. The default value is500。
docker update --blkio-weight 800 my_container
8、--pids-limit: Set the maximum number of processes the container can use.
- Format:
<number>, 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 the container's memory limit:
docker update -m 2g my_containerThis command updates the memory limit of my_container to 2GB.
2. Set the CPU core limit:
docker update --cpus 1.5 my_container
This command limits my_container to use at most 1.5 CPU cores.
3. Update the 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 the 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 limits
docker updateThe command takes effect immediately, but does not affect the applications running inside the container; the container continues to run.- Only supports adjusting container resource limits; other container configurations (such as environment variables, port mappings, etc.) cannot be modified.
other extensions