8.docker的系统资源限制

一、 概述

默认docker容器使用的memory资源和CPU资源是没有限制的,但是我们可以在docker run的时候通过选项去限制,具体参考官方文档。

[root@node1 ~]# docker run --help
    --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)
    --oom-kill-disable         Disable OOM Killer 
   --oom-score-adj int              Tune host's OOM preferences (-1000 to 1000)
--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)

 操作系统进程管理子系统中,最重要的组件之一,进程调度器(scheduler)。docker1.13以前版本配置使用CFS scheduler(Completely Fair Scheduler 完全公平调度器),在docker1.13及以后版本,也可以使用realtime scheduler。

进程:CPU密集型,IO密集型。

Tips:尽量不要以管理员账号运行容器,并且应该做好资源限制。

二、示例

[root@node1 ~]# docker pull lorel/docker-stress-ng  #压测工具
[root@node1 ~]# docker run --name stress --rm lorel/docker-stress-ng:latest stess --help #查看工具的帮助
[root@node1 ~]# docker run --name stress --rm -m 256m  lorel/docker-stress-ng:latest stess --help :latest stess --vm 2  #压测内存
[root@node1 ~]# docker top stress  #查看stress容器内运行进程的资源使用情况
[root@node1 ~]# docker stats    # 查看所有容器资源使用的动态变化
[root@node1 ~]# docker run --name stress --rm --cpus 0.5  lorel/docker-stress-ng:latest stess --cpu 4  #压测从CPU
[root@node1 ~]# docker top stress
[root@node1 ~]# docker stats

 

posted @ 2019-10-22 20:58  _幸会  阅读(192)  评论(0编辑  收藏  举报