I need to set the file descriptor limit correctly on the docker container I connect to container with ssh (https://github.com/phusion/baseimage-docker)
Already tried:
- edit limits.conf the container ignore this file
- upstart procedure found at https://coderwall.com/p/myodcq but this docker image has different kind of init process. (runit)
- I tried to modify configuration of pam library in /etc/pam.d
- try to enabled pam for ssh in sshd_config
The output it always the same.
bash: ulimit: open files: cannot modify limit: Operation not permitted
The latest docker supports setting ulimits through the command line and the API. For instance,
docker run
takes--ulimit <type>=<soft>:<hard>
and there can be as many of these as you like. So, for your nofile, an example would be--ulimit nofile=262144:262144
I have tried many options and unsure as to why a few solutions suggested above work on one machine and not on others.
A solution that works and that is simple and can work per container is:
After some searching I found this on a Google groups discussion:
That is because the ulimit settings of the host system apply to the docker container. It is regarded as a security risk that programs running in a container can change the ulimit settings for the host.
The good news is that you have two different solutions to choose from.
sys_resource
fromlxc_template.go
and recompile docker. Then you'll be able to set the ulimit as high as you like.or
I applied the second method:
sudo service docker stop;
changed the limits in /etc/security/limits.conf
reboot the machine
run my container
run
ulimit -a
in the container to confirm the open files limit has been inherited.See: https://groups.google.com/forum/#!searchin/docker-user/limits/docker-user/T45Kc9vD804/v8J_N4gLbacJ
Actually, I have tried the above answer, but it did not seem to work.
To get my containers to acknowledge the
ulimit
change, I had to update thedocker.conf
file before starting them:The
docker run
command has a--ulimit
flag you can use this flag to set the open file limit in your docker container.Run the following command when spinning up your container to set the open file limit.
docker run --ulimit nofile=<softlimit>:<hardlimit>
the first value before the colon indicates the soft file limit and the value after the colon indicates the hard file limit. you can verify this by running your container in interactive mode and executing the following command in your containers shellulimit -n
PS: check out this blog post for more clarity
For boot2docker, we can set it on
/var/lib/boot2docker/profile
, for instance:ulimit -n 2018
Be warned not to set this limit too high as it will slow down apt-get! See bug #1332440. I had it with debian jessie.