限制日志大小
步骤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