将Docker容器限制到单个CPU的内核 [英] Limiting a Docker Container to a single cpu core

查看:235
本文介绍了将Docker容器限制到单个CPU的内核的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个在一致的条件下运行代码的系统,而我想象的可能的一种方式是在Docker容器中运行不同的程序,具有相同的布局,保留相同的内存量等但是,我似乎无法弄清楚如何保持CPU使用率一致。



我似乎找到的最接近的东西是cpu共享,如果我了解文档,则限制cpu的使用方面与其他容器/其他进程有关在系统上运行,系统上有什么可用。他们似乎没有能力将容器限制在绝对量的cpu使用量。



理想情况下,我想设置码头集装箱,限制为使用单个cpu内核。这是可能的吗?

解决方案

如果您使用较新版本的Docker,可以使用在$ code> docker run 中指定要分配的CPU内核的-cpuset-cpus =

  docker run --cpuset-cpus =0[...] 

如果您使用旧版本的Docker(< 0.9),它使用LXC作为默认执行环境,则可以使用 - lxc-conf 配置分配的CPU内核:

  docker run --lxc-conf =lxc.cgroup.cpuset.cpus = 0[...] 

在这两种情况下,只有第一个CPU内核将可用于码头容器。这两个选项都记录在停靠站帮助中


I'm trying to build a system which runs pieces of code in consistent conditions, and one way I imagine this being possible is to run the various programs in docker containers with the same layout, reserving the same amount of memory, etc. However, I can't seem to figure out how to keep CPU usage consistent.

The closest thing I can seem to find are "cpu shares," which, if I understand the documentation, limit cpu usage with respect to what other containers/other processes are running on the system, and what's available on the system. They do not seem to be capable of limiting the container to an absolute amount of cpu usage.

Ideally, I'd like to set up docker containers that would be limited to using a single cpu core. Is this at all possible?

解决方案

If you use a newer version of Docker, you can use --cpuset-cpus="" in docker run to specify the CPU cores you want to allocate:

docker run --cpuset-cpus="0" [...]

If you use an older version of Docker (< 0.9), which uses LXC as the default execution environment, you can use --lxc-conf to configure the allocated CPU cores:

docker run --lxc-conf="lxc.cgroup.cpuset.cpus = 0" [...]

In both of those cases, only the first CPU core will be available to the docker container. Both of these options are documented in the docker help.

这篇关于将Docker容器限制到单个CPU的内核的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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