作者: 耗子007
update命令的主要作用:动态更新容器的配置。
注意:
- 可以同时指定多个容器, 容器之间以空格间隔
- 对于–kernel-memory,只能对stopped容器进行更新。其它的配置支持running或stoped的容器。
然后,看看官方手册,docker update的用法如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| Usage: docker update [OPTIONS] CONTAINER [CONTAINER...]
Update configuration of one or more containers
Options: --blkio-weight value Block IO (relative weight), between 10 and 1000 --cpu-period int Limit CPU CFS (Completely Fair Scheduler) period --cpu-quota int Limit CPU CFS (Completely Fair Scheduler) quota -c, --cpu-shares int CPU shares (relative weight) --cpuset-cpus string CPUs in which to allow execution (0-3, 0,1) --cpuset-mems string MEMs in which to allow execution (0-3, 0,1) --help Print usage --kernel-memory string Kernel memory limit -m, --memory string Memory limit --memory-reservation string Memory soft limit --memory-swap string Swap limit equal to memory plus swap: '-1' to enable unlimited swap --restart string Restart policy to apply when a container exits
|
CPU相关参数
cpu-shares参数:设置容器的CPU占用的相对权重,如果有两容器在一个核上面运行,一个cpu-shares设置为1024,一个设置为512,
那么这两个占用CPU时间的比例为2/1。
此功能和cpuset-cpus参数一起使用,结果比较容易呈现。
启动三个容器,cpu-shares分别为1024,1024,和512,cpuset-cpus=1。启动脚本如下(cpurun.sh就是一个while(1)):
1 2 3
| docker run -td --cpu-shares=512 --cpuset-cpus=1 -v /workspace:/test ubuntu sh -c "/test/cpurun.sh" docker run -td --cpu-shares=1024 --cpuset-cpus=1 -v /workspace:/test ubuntu sh -c "/test/cpurun.sh" docker run -td --cpu-shares=1024 --cpuset-cpus=1 -v /workspace:/test ubuntu sh -c "/test/cpurun.sh"
|
top查看三个进程的cpu占有率,结果如下:
1 2 3 4 5
| PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 17970 root 20 0 3852 1764 1104 S 15.0 0.0 0:19.35 sh 18172 root 20 0 3852 1764 1104 S 15.0 0.0 0:11.47 sh 850 root 20 0 223264 42416 13860 S 13.7 0.5 2:44.50 docker 28127 root 20 0 3464 1408 1104 S 8.0 0.0 0:01.25 sh
|
结果很明显,cpu占比的比例接近2:2:1.