mayTree
mayTree

Reputation: 797

Docker error: too many open files

I got that error message when creating container.

Error response from daemon: too many open files

But I couldn't find any information about that error. (I saw https://github.com/docker/libcontainer/issues/211, but that was not the same problem of it.) Is there anyone who knows about it?

Thanks.

Upvotes: 14

Views: 42904

Answers (4)

fastkiller
fastkiller

Reputation: 21

I ran into the same error while creating a Docker container and initially tried the accepted answer, but it didn’t resolve the issue for me. After some research, I found that the problem was related to the number of inotify.max_user_instances that could be created.

Here’s what worked for me:

  1. Temporarily increase the number of max_user_instances:
sudo sysctl -w fs.inotify.max_user_instances=256

If you want the change to persist across reboots:

  1. add the following line to your /etc/sysctl.conf file:
fs.inotify.max_user_instances=256
  1. Then apply the changes with:
sudo sysctl -p

For more details, I referred to this answer on AskUbuntu, which explains it bit more.

Upvotes: 0

steve
steve

Reputation: 3465

I can't believe this issue is not better solved already, I develop with Docker alot on my Mac so Docker is running in a tiny VM. I came across this issue about 2 years ago and it took me ages to find a work around and I hit the issue all the time. I forget where I found this "fix" but when ever I reboot my Mac I have to run this in order for my containers not to complain about "too many open files" - if I forget to run this then its not always obvious what the issue is either, sure a container will log the error somewhere but when you have dozens of containers running with detailed logging its difficult to track - anyway, the script is

#!/bin/bash
docker run -ti --privileged centos sysctl fs.inotify.max_user_instances=8192

Upvotes: 0

vumdao
vumdao

Reputation: 621

It's more convenient to set the ulimit inside the docker systemD service

Modify /usr/lib/systemd/system/docker.service

ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock $OPTIONS $DOCKER_STORAGE_OPTIONS $DOCKER_ADD_RUNTIMES --default-ulimit nofile=65535:65535

Upvotes: 3

mtyurt
mtyurt

Reputation: 3449

Default limit of number of open files is 1024. You can increase it in two ways:

  1. Run the container with --ulimit parameter:

    docker run --ulimit nofile=5000:5000 <image-tag>
    
  2. Run the container with --privileged mode and execute ulimit -n 5000.

You can find more information here.

Upvotes: 16

Related Questions