How to prevent docker containers from consuming the entire processor?

I'm a little new to Docker and this week came across a process in a container with a 100% processor. I did not set any resource limits for the container at startup, and this caused the entire server to stop responding. I could not stop the docker, kill the docker and, in the end, lost the ssh ability to the main machine. I have finished rebooting the machine.

I am looking for parameters that will allow the host machine to retain some processor capacity, so the above situation will not occur.

One thought is to use docker run --cpuset-cpuson all containers so that they cannot use CPU 0, which would remain only for use by the host. This approach seems wasteful.

Other options are less clear on how I can limit.

  • --cpu-shares will allow me to divide the total use by percent, which may leave me in the same situation described above.

  • --cpu-periodand --cpu-quotaless understood by me, but they don't seem to allow this.

Is there a way to reserve some percentage of the CPU for the host machine?

+4
source share

All Articles