Docker如何使用主机操作系统的CPU内核? [英] How does docker use CPU cores from its host operating system?

查看:684
本文介绍了Docker如何使用主机操作系统的CPU内核?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于Docker基于LXC的事实,我的描述是Docker容器从其主机操作系统共享各种资源。我关心的是CPU内核。这是一个场景:




  • 主机linux操作系统有8个内核

  • 我必须部署上面的主机操作系统上的docker容器集合。

  • 我需要部署的一些Docker容器将更适合使用2个核心



a)所以如果我运行该主机上的所有Docker容器,它们是否会根据需要使用CPU /内核,就像在主机操作系统上正常安装的应用程序一样运行? b / b
$ b

b)docker容器是否会消耗自己的进程,并且其中包含的所有处理都将被粘贴到该父进程的CPU内核中?



c)如何指定docker容器来使用多个内核(例如4)。我看到有一个可以指向核心ID的-C标志,但是看起来没有任何选择可以随意指定容器来选择N个内核。

解决方案

目前,我不认为docker提供这种级别的粒度。它没有指定在其lxc.conf文件中分配多少个内核,因此您可以获得每个Docker的所有内核,可能(或可能是1,我不是100%肯定的)。



但是,您可以调整为给定容器生成的conf文件,并设置类似于

  cpuset {
cpuset.cpus =0-3;
}


My understading, based on the fact that Docker is based on LXC, is that Docker containers share various resources from its host operating system. My concern is with CPU cores. Here is a scenario:

  • a host linux OS has 8 cores
  • I have to deploy a set of docker containers on the host OS above.
  • Some of the docker containers that I need to deploy would be better suited to use 2 cores

a) So if I run all of the docker containers on that host, will they consume CPU/cores as needed like if they were being run as normal installed applications on that host OS ?

b) Will the docker container consume its own process and all of the processing that is contained in it will be stuck to that parent process's CPU core ?

c) How can I specify a docker container to use a number of cores ( 4 for example ). I saw there is a -C flag that can point to a core id, but it appears there is no option to specify the container to pick N cores at random.

解决方案

Currently, I don't think docker provides this level of granularity. It doesn't specify how many cores it allocates in its lxc.conf files, so you will get all cores for each docker, potentially (or possibly 1, I'm not 100% sure on that).

However, you could tweak the conf file generated for a given container and set something like

cpuset {
    cpuset.cpus="0-3";
}

这篇关于Docker如何使用主机操作系统的CPU内核?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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