参考文档
https://blog.51cto.com/xujpxm/1961072 Linux的Linux MemFree与MemAvailable的区别
https://blog.csdn.net/csdn_immortal/article/details/86671705 linux的cpu和内存命令解析
docker 内存和cpu限制1
docker 内存和cpu限制2
docker stats ID CPU显示不正确
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
023122c0681f os1 0.00% 12.22MiB / 1GiB 1.19% 11.9MB / 133kB 4.31MB / 111kB 1
这里的CPU %显示的单个cpu的百分比,实际容器分配的cpu没有地方查。应该只有docker inspect
可以看了。
为啥这些资料只有当你懂了之后才能看懂,不懂之前怎么看都不懂
docker的内存和cpu限制
^C ✘ xiaoyu@xiaoyudeMacBook-Pro ~ docker run --help | grep -i cpu
--cpu-period int Limit CPU CFS (Completely Fair Scheduler) period
--cpu-quota int Limit CPU CFS (Completely Fair Scheduler) quota
--cpu-rt-period int Limit CPU real-time period in microseconds
--cpu-rt-runtime int Limit CPU real-time runtime in microseconds
-c, --cpu-shares int CPU shares (relative weight)
--cpus decimal Number of CPUs
--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)
xiaoyu@xiaoyudeMacBook-Pro ~ docker run --help | grep -i mem
--cpuset-mems string MEMs in which to allow execution (0-3, 0,1)
--kernel-memory bytes Kernel memory limit
-m, --memory bytes Memory limit
--memory-reservation bytes Memory soft limit
--memory-swap bytes Swap limit equal to memory plus swap: '-1' to enable unlimited swap
--memory-swappiness int Tune container memory swappiness (0 to 100) (default -1)
xiaoyu@xiaoyudeMacBook-Pro ~
xiaoyu@xiaoyudeMacBook-Pro ~
使用stress命令测试一下
使用alpine容器,运行容器:docker run --name os1 -it -m 1g --cpus=2 alpine:3.12 bash
,然后安装stress软件
apk更换源:
使用阿里源镜像
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
使用科大镜像
sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
apk update
apk add stress-ng
stress-ng --help
stress-ng -c 1 --timeout 100
然后使用docker stats os1
查看