4

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.

bitmask
  • 32,434
  • 14
  • 99
  • 159

2 Answers2

6

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.

allprog
  • 16,540
  • 9
  • 56
  • 97
user2105103
  • 11,599
  • 2
  • 18
  • 11
  • `--privileged=true` works like charm (it would appear my docker version is not bleeding edge). Thank you. – bitmask Sep 25 '14 at 21:03
  • 2
    On my system, I got `docker: Error response from daemon: linux spec capabilities: Unknown capability to add: "CAP_CAP_SYS_NICE".` Using `--cap-add=SYS_NICE` worked. – Dave Yarwood Aug 18 '17 at 17:36
1

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

Andy
  • 35,844
  • 6
  • 43
  • 50