I have a bunch of Docker apps running on one server, and things got tricky when Docker builds decided to grab all the CPU, causing all my other apps to run slowly. So, how did I fix it? The answer is the
Whenever I run
docker build ..., my CPU utilization goes through the roof 🤯
This would be fine if there isn't anything else on the server, but there are some apps that are super sensitive to this kind of CPU hogging, so I needed to find a solution!
--cpu-quota flag is described as "Limit the CPU CFS (Completely Fair Scheduler) quota", which I honestly didn't understand the first time I read it.
The TL;DR version is that every core you have equals
100000. If you have a server with 1 core and you want to give docker build 80% of the available CPU, you use
--cpu-quota 80000. And if you have more cores, you simply scale it up. If you have 4 cores, it would be 4 times 80000, or 320000.
That's it! If you simply append
--cpu-quota xyz to your docker build, your problems are solved. Of course, you need to figure out what your magic number! For me, 70% of the available CPU solved all my issues.
If you don't want to have the same issue while deploying Docker on your Server, check out Sliplane!