Reputation: 11
I've run into something that I cannot quite wrap my head around so I thought I'd turn to smarter minds than mine.
My problem is that I'm trying to figure out how Docker interacts with the Host CPU and which of Docker and Host have priority use over the resources. I want the CPU usage of the host to take priority over the container.
What I have done so far is I started a regular Ubuntu container and I monitor the performance of that container with cAdvisor. I then ran a CPU hog inside the container using the linux stress tool, hogging all cores.
stress -c 8
After confirming that the container did indeed use 100% CPU I ran the same command on the host hogging all 8 cores. What I expected to see was that that container's CPU usage would drop to close to 0% since the host was now using all the resources. What I instead saw was the following:
So it would seem the container and the Host evenly share the CPU resources. I've also tried running the stress tool on the host with a niceness value of -20 with the same result as above.
Is there any way setting CPU priority to the host so that Docker container would use almost nothing of the CPU resources when the host was using all of them?
Thankful for any help I can get!
Upvotes: 1
Views: 3708
Reputation: 1614
There are several options to limit the processor usage of the containers, by for instance setting cpu-period, cpu-quota and cpuset-cpus.
The following would limit the container processor usage to 33%.
docker run -it --cpu-quota=33000 ubuntu:latest /bin/bash
The options are described in the Docker documentation here: https://docs.docker.com/engine/reference/run/
Upvotes: 1