问题
Running a command via docker does not seem to adhere to my currently configured ulimits:
$ ulimit -t 5 ~ $ sudo -- bash -c "ulimit -t" 5 ~ $ sudo -- docker run --rm debian:wheezy bash -c "ulimit -t" unlimited
How can I make it do that?
回答1:
You can set global limits in the Docker daemon config. On Ubuntu, this is managed in Upstart. Add limit cpu <softlimit> <hardlimit> to /etc/init/docker.conf and restart the daemon.
On a per container basis, you must use the --privileged flag with docker run in order to set ulimits. AFAIK there is no way to do it without --privileged.
See also Runtime constraints on CPU and memory.
回答2:
Currently (v1.5.0) these limits are inherited from the docker daemon's limits. But docker team is about to release limits per containers.
For a workaround you can set the limits inside the container like
# docker run ubuntu bash -c "ulimit -t 5; doSomething"
来源:https://stackoverflow.com/questions/25744278/how-to-make-docker-run-inherit-ulimits