问题
I'm currently attempting to develop a sandbox using Docker. Docker spawns process through a running daemon, and I am having a great deal of trouble enabling the limits set forth in the limits.conf file such that they apply to the daemon. Specifically, I am running a forkbomb such that the daemon is the process that spawns all the new processes. The nproc limitation I placed on the user making this call doesn't seemed to get applied and I for the life of me can not figure out how to make it work. I'm quiet positive it will be as simple as adding the correct file to /etc/pam.d/, but I'm not certain.
回答1:
The PAM limits only apply to processes playing nice with PAM. By default, when you start a shell in a container, it won't have anything to do with PAM, and setting limits through PAM just won't work.
Here are some other ways to make it happen!
- Instead of starting your process immediately, you can start a tiny wrapper script, which will do the appropriate - ulimitcalls before executing your process.
- If you want an interactive shell, you can run - login -f <username>(e.g.- login -f root); that will use the normal login process to auto-log you on the machine (and that should go through the normal PAM mechanisms).
- If you want all containers to be subject to those limits, you can set the limits on your system, then restart Docker with those lower limits; containers are created by Docker, and by default, they will inherit those limits as well. 
来源:https://stackoverflow.com/questions/21979137/enable-pam-configuration-limits-conf-for-a-running-daemon