Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a docker container be run `nice`ly?

Tags:

docker

nice

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?

like image 794
rjmunro Avatar asked Jan 15 '19 16:01

rjmunro


People also ask

Can a Docker container run on any OS?

You can run both Linux and Windows programs and executables in Docker containers. The Docker platform runs natively on Linux (on x86-64, ARM and many other CPU architectures) and on Windows (x86-64). Docker Inc. builds products that let you build and run containers on Linux, Windows and macOS.

Does Docker offer support for IPv6?

Before you can use IPv6 in Docker containers or swarm services, you need to enable IPv6 support in the Docker daemon. Afterward, you can choose to use either IPv4 or IPv6 (or both) with any container, service, or network. Note: IPv6 networking is only supported on Docker daemons running on Linux hosts.

Can Docker run bare metal?

Docker is more limited and can run only on Linux, certain Windows servers and IBM mainframes if hosted on bare metal. For example, Docker runs natively only on bare-metal Windows servers running Windows Server 2016 or later.

Do Docker containers run forever?

By default, containers run only as long as their default command executes but a common use case it´s to run them indefinitely for debugging and troubleshooting purposes.


1 Answers

docker-processes are usual OS processes.

Docker or not is not a concern for process scheduler.

So nice/renice works for docker-processes in the same way as for others.

like image 89
Alex Yu Avatar answered Sep 19 '22 13:09

Alex Yu