默认情况下,容器没有资源的限制,它可以使用整个主机的所有资源。Dcoker提供了控制资源的方法,
 多少内存,CPU,IO,都可以在docker run使用标志符来设置。
 
内存

Docker可以强制执行硬内存限制,允许容器使用不超过给定数量的用户或系统内存,
或软限制,允许容器使用所需的内存,除非满足某些条件,例如 内核检测到主机上的低内存或争用。
当单独使用或设置多个选项时,这些选项中的一些具有不同的效果。
选项 说明
-m or --memory=
容器能使用的最大的内存。
如果你设置了这个选项,最小允许使用的值为4M。
--memory-swap*
容器允许swap的内存大小。
更多细节:--memory-swap details.
--memory-swappiness
默认情况下,不需要设置。
主机内核可以让容器使用一定比例的匿名内存页。你可以通过这个参数来设置这个百分比。更多细节: --memory-swappiness details.
--memory-reservation 允许你指定软限制,比--memory 参数值要小。这软限制在Docker检测到主机上的连接或内存较少时激活。
--kernel-memory
容器可以使用的最大的内核内存。最小值是4M。 因为内核内存不能被交换出去,一个缺少内核内存的容器可能会阻碍主机的资源,这会对主机和其他容器产生负面影响。
更多细节:--kernel-memory details.
--oom-kill-disable 默认情况下:out-of-memory(oom)内存溢出的错误出现,内核杀死容器中的进程。使用--oom-kill-disable 可以改变这种行为。 仅仅在已经设置了-m 的容器中关闭 OOM 杀死。 如果-m 标志没有设置,主机可能耗尽内存,内核可能需要杀死主机系统进程来释放内存。
--memory-swap 细节
  • 如果没有设置,而--me内核内存限制以分配给容器的总内存来表示。mory设置如300m了,则swap默认为300*2=600M
  • 如果--memory,--memory-swap都设置了
    • --memory-swap 代表了可以使用的总共内存,--memory 代表不使用swap的内存
    • 如:--memory-swap=1g,--memory=300M,
      • docker可以使用300M内存,1g-300m=700m swap.
  • 如果设置为-1,则容器不限制使用swap 内存。
 
 
CPU

Option Description
--cpu-shares Set this flag to a value greater or less than the default of 1024 to increase or reduce the container’s weight, and give it access to a greater or lesser proportion of the host machine’s CPU cycles. This is only enforced when CPU cycles are constrained. When plenty of CPU cycles are available, all containers use as much CPU as they need. In that way, this is a soft limit. --cpu-sharesdoes not prevent containers from being scheduled in swarm mode. It prioritizes container CPU resources for the available CPU cycles. It does not guarantee or reserve any specific CPU access.
--cpu-period 容器上一个逻辑CPU的调度周期. --cpu-periodmor默认值是100000(100ms)
--cpu-quota 在由--cpu-period设置的时间段内容器可以调度的最大时间量。
--cpuset-cpus 使用这个选项指定CPU使用一个或者多个CPU核,并用逗号分隔。
 
--cpu-period 和 --cpu-qota
例子:如果你有1核的CPU系统,容器run使用--cpu-period=100000
--cpu-quota=50000,容器可以消耗高达50%的1个CPU
$ docker run -ti --cpu-period= --cpu-quota= busybox
如果你有4核的CPU系统,容器运行--cpu-period=100000
--cpu-quota=200000,容器可以使用最多2个逻辑CPU(--cpu-period的200%)
$ docker run -ti --cpu-period= --cpu-quota=
--cpu-set-cpus
给容器实际4核的CPU
$ docker run -ti --cpuset-cpus= busybox
 
阻塞IO

有两个选项可用于调整给定容器对直接块IO设备的访问。
您还可以按照每秒的字节数或每秒的IO操作来指定带宽限制。
 
Option Description
blkio-weight By default, each container can use the same proportion of block IO bandwidth (blkio). The default weight is 500. To raise or lower the proportion of blkio used by a given container, set the --blkio-weight flag to a value between 10 and 1000. This setting affects all block IO devices equally.
blkio-weight-device The same as --blkio-weight, but you can set a weight per device, using the syntax --blkio-weight-device="DEVICE_NAME:WEIGHT" The DEVICE_NAME:WEIGHT is a string containing a colon-separated device name and weight.
--device-read-bps and--device-write-bps Limits the read or write rate to or from a device by size, using a suffix of kbmb, or gb.
--device-read-iops or--device-write-iops Limits the read or write rate to or from a device by IO operations per second.
如果指定--blkio-weight和-blkio-weight-device,Docker使用--blkio-weight作为默认权重,
并使用--blkio-weight-device重写命名设备上的默认值。
 
要将/ dev / sda的容器的设备权重设置为200,而不指定默认blkio-weight:
$ docker run -it \
--blkio-weight-device "/dev/sda:200" \
ubuntu
此示例将ubuntu容器限制为从/ dev / sda到每秒1000次IO操作的最大读取速率:
$ docker run -ti --device-read-iops /dev/sda: ubuntu
总结

 
  • 默认容器没有资源的限制,Docker提供了控制方法;

    • 内存,CPU,IO
    • docker run + 标志符来设置
  • 主要参数
    • 内存

      • -m 容器能使用的最大内存
      • --memory--reservation 
        • 比-m的值要小,在docker检测到主机的内存较少时激活
    • CPU
      • --cpu-period, --cpu-quota
      • 允许容器使用50%的CPU
        • --cpu-period = 10 ,--cpu-quota=5
      • 允许容器使用主机4核中的两核
        • --cpu-period = 10 , --cpu-quota=20
    • IO
      • 控制每秒的字节数或每秒的IO操作来限制带宽
      • 限制从/dev/sda 每秒1000次的IO读取操作
        • docker run -ti --device-read-iops /dev/sda:1000 ubuntu

最新文章

  1. Drools 查询学习
  2. java实现文件上传--flash上传
  3. CRUD Operations In ASP.NET MVC 5 Using ADO.NET
  4. sqlite3中的数据类型
  5. java 多线程 CountDownLatch用法
  6. SQL中两种表复制语句
  7. 查看,添加和删除GIT配置的正确姿势
  8. JSP标签JSTL的使用(1)--表达式操作
  9. ArcGIS API for JavaScript 入门教程[3] 你看得到:数据与视图分离
  10. adb 查看 android手机的CPU架构
  11. Java二叉树实现及递归与非递归遍历实现
  12. java使用google开源工具实现图片压缩
  13. WinRAR试用过期决绝方法
  14. BZOJ3632:外太空旅行(最大团,DFS)
  15. layer的用法
  16. OpenCL 双调排序 GPU 版
  17. “全栈2019”Java多线程第二十三章:活锁(Livelock)详解
  18. velocity+spring mvc+spring ioc+ibatis初试感觉(与struts+spring+hibernate比较)
  19. 如何在Oracle官网下载java的JDK最新版本和历史版本
  20. 算法笔记_040:二进制幂(Java)

热门文章

  1. 手机端sticker布局,底部按钮在屏幕底部
  2. msconfig.exe
  3. 分布式存储系统可靠性系列五:副本放置算法 & CopySet Replication
  4. struts ValueStack 详解
  5. 【转】unity自带寻路Navmesh入门教程(二)
  6. 习题:八数码难题(双向BFS)
  7. httpClient get方式抓取数据
  8. FreeBSD查看带宽占用情况,CPU,硬盘IO 虚拟内存等命令
  9. Hibernate逆向工程生成代码
  10. POJ3170 Bzoj1671 [Usaco2005 Dec]Knights of Ni 骑士