I have systemd running inside a docker container and I'm trying to set Number of File Descriptors limit for the service. I set the limit on the docker container to 262k, but for some reason the /sbin/init process lowers the limit to 65k. Here's a simple example:

$ sudo docker run --rm --ulimit nofile=262144:262144 --entrypoint grep centos:7.6.1810 files /proc/1/limits
Max open files            262144               262144               files
$ sudo docker run -d --name test --ulimit nofile=26144:26144 --entrypoint /sbin/init centos:7.6.1810 && sudo docker exec test grep files /proc/1/limits && sudo docker rm -f test
Max open files            26144                26144                files
$ sudo docker run -d --name test --ulimit nofile=262144:262144 --entrypoint /sbin/init centos:7.6.1810 && sudo docker exec test grep files /proc/1/limits && sudo docker rm -f test
Max open files            65536                65536                files     

In the first command I'm running a simple grep command, you can see it gets the 262k limit I set on the container. Second command I start the /sbin/init process with 26k limit, which it follows. If I set the limit >65k (3rd command), it is ignored and set to 65k instead.

Since the init process is the parent of all the services and it sets nofile hard limit to 65k, it is impossible for my service to go beyond 65k (with for example LimitNOFILE= setting on the service). Is there a way to prevent init from setting a lower nofile limit?

EDIT: The 3rd command gives the expected output on my own machine. The output above is from an AWS EC2 instance. Not sure why its different...


This works as expected with centos:7.7.1908 image, so I guess something was fixed in systemd.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.