如何通过docker run将50%的CPU资源分配给docker容器? [英] How to allocate 50% CPU resource to docker container via `docker run`?

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

问题描述

我有一个4核CPU,我想为Docker容器分配50%的CPU资源。

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

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

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是一个相对权重,相对于默认设置1024,因此,如果您有两个运行在同一核心上的容器,则可以给它们CPU 50-50或80-20或任何您想要的数字,都可以通过调整数字来实现。它是一个整数。

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.

您不能使用此标志给出总体限制,但是您可以使用来限制容器运行的CPU数量。 -cpuset

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.

数字1024在 Cgroups文档

这篇博客文章(来自Marek Goldmann)介绍了Docker中的资源管理。

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

请参阅还为Docker容器设置CPU的绝对限制,其中说可以使用lxc(旧的Docker实现)来完成,而不能使用libcontainer(当前的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 run将50%的CPU资源分配给docker容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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