Reputation: 2088
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:
The output it always the same.
bash: ulimit: open files: cannot modify limit: Operation not permitted
Upvotes: 66
Views: 219376
Reputation: 1
To set the max_locked_memory while doing docker build itself add the following argument,
docker build --ulimit memlock=-1
which sets the max_locked_memory to unlimited(which can be viewed by using ulimit -l
). This is because docker build is running in a seperate user space and has its own File system. As we don't want it to take the host machine's specifications we are adding this command line argument.
To replicate the same changes inside the docker container, run the docker image with the same command
Ex, docker run --ulimit memlock=-1
Upvotes: 0
Reputation: 475
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/compose-file-v3/
Upvotes: 23
Reputation: 6551
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
Upvotes: 4
Reputation: 139
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
Upvotes: 9
Reputation: 69
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
Upvotes: 2
Reputation: 2088
After some searching I found this on a Google groups discussion:
docker currently inhibits this capability for enhanced safety.
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
from lxc_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
Upvotes: 34
Reputation: 5776
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
Upvotes: 76
Reputation: 136
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.
Upvotes: 1
Reputation: 4465
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
Upvotes: 5