Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set negative niceness of a docker process?

I have a testenvironment for code in a docker image which I use by running bash in the container:

me@host$ docker run -ti myimage bash

Inside the container, I launch a program normally by saying

root@docker# ./myprogram

However, I want the process of myprogram to have a negative niceness (there are valid reasons for this). However:

root@docker# nice -n -7 ./myprogram
nice: cannot set niceness: Permission denied

Given that docker is run by the docker daemon which runs as root and I am root inside the container, why doesn't this work and how can force a negative niceness?

Note: The docker image is running debian/sid and the host is ubuntu/12.04.

like image 472
bitmask Avatar asked Mar 18 '23 09:03

bitmask


2 Answers

Try adding

--privileged=true

to your run command.

[edit] privileged=true is the old method. Looks like

--cap-add=SYS_NICE

Should work as well.

like image 95
user2105103 Avatar answered Apr 01 '23 11:04

user2105103


You could also set the CPU priority of the whole container with -c for CPU shares.

  • Docker docs: http://docs.docker.com/reference/run/#runtime-constraints-on-cpu-and-memory
  • CGroups/cpu.shares docs: https://www.kernel.org/doc/Documentation/scheduler/sched-design-CFS.txt
like image 25
Andy Avatar answered Apr 01 '23 11:04

Andy