如何为docker容器分配50%的CPU资源? [英] How to allocate 50% CPU resource to docker container?

查看:866
本文介绍了如何为docker容器分配50%的CPU资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个4核CPU,我想分配50%的CPU资源给码头容器。

阅读 docker-run 手册和 config.go 源代码。

我还不知道如何使用 -c,--cpu-shares = 0 选项。

  docker run -c 0.5  - i -t ubuntu / bin / bash 



#pre> $ code> docker run -c 2 -i -t ubuntu / bin / bash


解决方案

cpu-share是相对于默认设置为1024的相对权重,所以如果你有两个容器在同一个核心上运行,你可以给他们CPU 50-50或80-20或任何您想通过调整数字。它是一个整数。



您不能使用此标志给出整体限制,但您可以使用该标志限制容器运行的CPU集 - cpuset



1024号是在 Cgroups docs



Marek Goldmann的这篇博文解释了Docker的资源管理。



另请参见为Docker容器设置CPU的绝对限制 ,它说可以用lxc(较老的Docker实现)来完成,而不是libcontainer(当前的Docker实现)。


I have a 4-core CPU, I want to allocate 50% CPU resource to a docker container.
After reading the docker-run manual and config.go source code.
I still don't know how to use the -c, --cpu-shares=0 option.

docker run -c 0.5 -i -t ubuntu /bin/bash

Or

docker run -c 2 -i -t ubuntu /bin/bash

解决方案

cpu-shares is a 'relative weight', relative to the default setting of 1024, so if you had two containers running on the same core, you could give them the CPU 50-50 or 80-20 or whatever you wanted by adjusting the numbers. It is an integer.

You cannot give an overall limit, as you want to, using this flag, but you can restrict the set of CPUs that the container runs on using --cpuset mentioned here.

The number 1024 is in the Cgroups docs.

This blog post from Marek Goldmann explains resource management in Docker.

See also Setting absolute limits on CPU for Docker containers, which says it can be done with lxc (older Docker implementation) but not libcontainer (current Docker implementation).

这篇关于如何为docker容器分配50%的CPU资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆