How does docker use CPU cores from its host operating system? How does docker use CPU cores from its host operating system? docker docker

How does docker use CPU cores from its host operating system?


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";}


It might be that things changed in the latest (few) versions. Nowadays you can constrain your docker container with parameters for docker run:The equivalent for the current answer in the new docker version isdocker run ubuntu /bin/echo 'Hello world --cpuset-cpus="0-3"However, this will limit the docker process to these CPU, but (please correct me if I am wrong) other containers could also request the same set. A possibly better way would be to use CPU shares.

For more information see https://docs.docker.com/engine/reference/run/


From ORACLE documentation:

  To control a container's CPU usage, you can use the  --cpu-period  and --cpu-quota options with the docker   create and docker run commands  from version 1.7.0 of Docker onward.  The --cpu-quota option specifies the number of microseconds   that a container has access to CPU resources during a   period specified by --cpu-period.  As the default value of --cpu-period is 100000, setting the   value of --cpu-quota to 25000 limits a container to 25% of   the CPU resources. By default, a container can use all available CPU resources,   which corresponds to a --cpu-quota value of -1.