Docker资源限制

九、Docker资源限制

  • 内存资源
-m or --memory=  #限制内存大小 例: --memory=4m
--memory-swap *  #限制交换分区,必须先设置内存大小,可设置的值:正数,0,-1
	正数:swap为swap-memory
	0:swap为物理机mem*2
	-1:不限制
	注意:在容器内free看到的swap不具有展现出空间指示的意义
--oom-kill-disable  #禁止容器被oom
  • CPU资源
--cpu-shares  #CPU资源共享,按比例切分当前系统上的CPU资源
--cpuset-cpus=0,1  #限制在哪个CPU上
--cpus=  #分配几个CPU
  • 压测
# docker pull lorel/docker-stress-ng
# docker run --name stress -it --rm -m 256m lorel/docker-stress-ng stress --vm 2
# docker top stress
# docker state
# docker run --name stress -it --rm --cpus 2 lorel/docker-stress-ng stress  --cpu 8
# docker run --name stress -it --rm --cpuset-cpus 0,2 lorel/docker-stress-ng stress  --cpu 8
# docker run --name stress -it --rm --cpu-shares 1024 lorel/docker-stress-ng stress  --cpu 8
# docker run --name stress2 -it --rm --cpu-shares 512 lorel/docker-stress-ng stress  --cpu 8
posted @ 2019-06-15 20:25  生生不息.连绵不绝  阅读(190)  评论(0编辑  收藏  举报