The default limit for open files is 1024 in Docker containers. In Unix systems, you can increase the limit by following command:

$ ulimit -n 90000

which sets the limit to 90000. However, Docker does not let you increase limits by default (assuming the container based on Unix, not Windows). To increase the open file limit in Docker, there are two options.

1. Argument to docker run or docker create

Just run the container with --ulimit flag:

$ docker run --ulimit nofile=90000:90000 <image-tag>

First 90000 is soft limit, second 90000 is hard limit. When you launch the container, of course with -it flag, and enter command ulimit -n you’ll see the limit is 90000 now.

You can find more info about --ulimit flag in the documentation.

2. Run docker in privileged mode

Docker containers are in unprivileged mode by default. You can increase the limit just like a regular Unix system when you run the container with privileged mode. Here is how:

$ docker run --privileged --it <image-tag>
# ulimit -n 
# ulimit -n 90000
# ulimit -n

Be careful, privileged mode is less contained. You can find more info about details of privileged mode in here and here

I prefer to use --ulimit flag because it’s better and safer than running the container in privileged mode.

I like to use the containers with least security allowance as much as possible, deny everything by default and allow only what’s needed.