如何检查Docker容器使用的核心数? [英] How to check the number of cores used by docker container?

查看:2265
本文介绍了如何检查Docker容器使用的核心数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经与Docker合作了一段时间,我已经安装了docker并使用

I have been working with Docker for a while now, I have installed docker and launched a container using

docker run -it --cpuset-cpus=0 ubuntu

当我登录到Docker控制台并运行

When I log into the docker console and run

grep processor /proc/cpuinfo | wc -l

它显示3,这是我在主机上拥有的内核数。

It shows 3 which are the number of cores I have on my host machine.

关于如何将资源限制到容器以及如何验证限制的任何想法?

Any idea on how to restrict the resources to the container and how to verify the restrictions??

推荐答案

容器不是完整的虚拟机。某些内核资源仍会像在主机上一样显示。

Containers aren't complete virtual machines. Some kernel resources will still appear as they do on the host.

在这种情况下,-cpuset-cpus = 0 修改容器cgroup可以访问的资源,而不是容器可以看到什么。

In this case, --cpuset-cpus=0 modifies the resources the container cgroup has access to, not what the container can see.

一种验证方法是运行容器中的 stress-ng 工具:

One way to verify is to run the stress-ng tool in a container:

使用1个cpu会固定在1个核心(正在使用的1个/ 3个核心,根据您使用的工具,100%或33%):

Using 1 cpu will be pinned at 1 core (1 / 3 cores in use, 100% or 33% depending on what tool you use):

docker run --cpuset-cpus=0 deployable/stress -c 3

这将使用2个内核(2/3核心,200%/ 66%):

This will use 2 cores (2 / 3 cores, 200%/66%):

docker run --cpuset-cpus=0,2 deployable/stress -c 3

这将使用3个(3/3核,300%/ 100%):

This will use 3 ( 3 / 3 cores, 300%/100%):

docker run deployable/stress -c 3

内存限制是内核统计中未显示的另一个区域

Memory limits are another area that don't appear in kernel stats

$ docker run -m 64M busybox free -m
             total       used       free     shared    buffers     cached
Mem:          3443       2500        943        173        261       1858
-/+ buffers/cache:        379       3063
Swap:         1023          0       1023

yamaneks答案包括 github问题

这篇关于如何检查Docker容器使用的核心数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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