登录
    Technology changes quickly but people's minds change slowly.

docker 限制日志大小 以及cpu 占比

技术宅 破玉 1551次浏览 0个评论

限制日志大小

步骤1:查看容器日志大小:
假设容器目录为/var/lib/docker/containers,那么执行如下命令

cd /var/lib/docker/containers 
du -sh *

步骤2:重新运行容器,增加日志参数
docker run增加如下参数,限制生成的json.log单个文件大小和保留文件个数:

--log-opt max-size=100m --log-opt max-file=3

限制CPU占比

–cpus 选项支持 cpu 占比
官方文档:

Specify how much of the available CPU resources a container can use. For instance, if the host machine has two CPUs and you set –cpus=”1.5″, the container is guaranteed at most one and a half of the CPUs. This is the equivalent of setting –cpu-period=”100000″ and –cpu-quota=”150000″. Available in Docker 1.13 and higher.

例如:

docker run -it --rm --cpus=2 u-stress:latest /bin/bash

华裳绕指柔, 版权所有丨如未注明 , 均为原创|转载请注明docker 限制日志大小 以及cpu 占比
喜欢 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址