I have a docker image that hosts a web server and another that runs background tasks. Most of the time the web server is idle, and the background tasks should be allowed to use 100% of the CPUs, but any time the web server needs resources, it should have priority on the CPUs so it can respond quickly.
If everything was running on one linux machine, I could use something like nice -n19 background-task
to run the tasks, and they would allow the web server as much CPU as it needed.
Is there a way to run the whole container at a nice
level? I know I can restrict the amount of CPU time available to each background task with cpu_quota, but this doesn't solve the problem. If the web server wants to use all 4 CPU cores to serve a client it should be allowed. If the web server is not busy, all 4 CPU cores should work on the background task.
If I change the command in the Dockerfile to:
nice -n19 background-task
Will this work between containers? Processes inside containers are all kind of normal processes running on the same kernel, so it seems like it will, but I'm not sure.
This seems like something fairly obvious to do. Am I missing something?