How to Configure Openfiles Limit for Docker Containers
The Ask
From the docker host (CentOS 7) is possible to see that the open files limit is set to 1024.
# ulimit -a | grep open
open files (-n) 1024
But the docker container has this limit set to 1048576
[root@e86ee2f0f6a0 /]# ulimit -a | grep open
open files (-n) 1048576
Is it possible to change this value for the docker containers?
The Answer
The open files limit is set by default to 1048576. This limit is not related to the host’s limit. There are 2 possible way how to change this limit:
global change (affects all containers)
- In this case please modify the following lines in the /usr/lib/systemd/system/docker.service
# vi /usr/lib/systemd/system/docker.service
LimitNOFILE=1048576
LimitNPROC=1048576
- Reload daemon config and restart the docker service.
# systemctl daemon-reload
# systemctl restart docker
Change specific container limit
In this case please run the container with the following option:
# docker run -it --ulimit nofile=122880:122880 centos
here,
122880 is the hard and soft open files limit for the container “centos”.
