Docker容器使用多少个CPU? [英] How many CPUs does a docker container use?

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

问题描述

可以说我正在docker容器内运行


Lets say I am running a multiprocessing service inside a docker container spawning multiple processes, would docker use all/multiple cores/CPUs of the host or just one?

解决方案

As Charles mentions, by default all can be used, or you can limit it per container using the --cpuset-cpus parameter.

docker run --cpuset-cpus="0-2" myapp:latest

That would restrict the container to 3 CPU's (0, 1, and 2). See the docker run docs for more details.


The preferred way to limit CPU usage of containers is with a fractional limit on CPUs:

docker run --cpus 2.5 myapp:latest

That would limit your container to 2.5 cores on the host.


Lastly, if you run docker inside of a VM, including Docker for Mac, Docker for Windows, and docker-machine, those VM's will have a CPU limit separate from your laptop itself. Docker runs inside of that VM and will use all the resources given to the VM itself. E.g. with Docker for Mac you have the following menu:

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

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