docker cpu和内存限制

参考文档

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查看

docker inspect查看容器的cpu和内存

请添加图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值