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 trie
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
Here is what I did.
set
ulimit -n 32000
in the file /etc/init.d/docker
and restart the docker service
docker run -ti node:latest /bin/bash
run this command to verify
user@4d04d06d5022:/# ulimit -a
should see this in the result
open files (-n) 32000
[user@ip ec2-user]# docker run -ti node /bin/bash
user@4d04d06d5022:/# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 58729
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 32000
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 58729
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
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 shell ulimit -n
PS: check out this blog post for more clarity
If using the docker-compose file, Based on docker compose version 2.x We can set like as below, by overriding the default config.
ulimits:
nproc: 65535
nofile:
soft: 26677
hard: 46677
https://docs.docker.com/compose/compose-file/
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:
docker run --ulimit memlock=819200000:819200000 -h <docker_host_name> --name=current -v /home/user_home:/user_home -i -d -t docker_user_name/image_name
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 the docker.conf
file before starting them:
$ sudo service docker stop
$ sudo bash -c "echo \"limit nofile 262144 262144\" >> /etc/init/docker.conf"
$ sudo service docker start