LoginSignup
3
1

More than 3 years have passed since last update.

DockerでCPUの使用量制限をする(--cpus)

Posted at

概要

Dockerには使えるCPUのコア(スレッド)数を制限する機能があります。

0.1コア分だけ使用する
docker update --cpus 0.1 container 
docker create -it --cpus 4.5 --storage-opt size=120G fedora /bin/bash

最小単位が0.01から、最大で搭載しているコアの数まで上げられます。
これと言って特定のコアにやらせるわけではないので、OSが勝手に実際に使うコアを指定します。

docker updateの場合には即座に制限が有効になるようです。

仕組み

例えば、

docker update --cpus 0.1 container 

とした場合、

docker inspect container 
・・・
"HostConfig": {
 "NanoCpus": 100000000,
・・・

とされます。

NanoCPU つまり

100000000 NanoCPU = 0.1 CPUコア

という等式が成り立ちます。

NanoCPUというのは

CPU quota in units of 10-9 CPUs.

1CPUを109区切りにした値のようです。
ところが、なぜこのような奇妙な分け方をするのは明らかではありません。
小数点を入れないようにするためでしょうか。

関連記事

参考文献

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1