How to make `docker run` inherit ulimits

杀马特。学长 韩版系。学妹 提交于 2019-12-10 17:47:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!