This blog will illustrate how to set the ulimit or file descriptor on the Docker container.
How to Set Ulimits or File Descriptor on Docker Container?
To set the ulimits or file descriptor on the Docker container, first, create an image. After that, create and set the ulimits or file descriptor on the Docker container using the “–ulimit” option. To set the ulimits or file descriptor on the Docker container, go through provided steps.
Step 1: Define Dockerfile Instructions
First, create a Dockerfile that includes the instructions to dockerize the application. For instance, we have dockerized the “index.html” program:
COPY index.html /usr/share/nginx/html/index.html
ENTRYPOINT ["nginx", "-g", "daemon off;"]
Step 2: Generate Docker Image
Next, generate the new Docker image by utilizing the Dockerfile instructions through the given command:
Step 3: Build Container and Set Ulimits of Container
After that, build and run the container using the “docker run” command. Also, set the file descriptor or ulimits on the container using the “–ulimit” option and set its value as “nofile=soft-ulimit:hard:ulimit”:
Check if the container is executing or not by navigating to the assigned port of the local host:
Step 4: Check Container’s Ulimit
In order to check if the ulimits is set on a Docker container or not, run the “docker exec” command. Here, the “-it” option is utilized to run the specified container interactively and allocate the TTY-pseudo terminal:
After that, check the containers ulimits by executing the “ulimit -n” command:
Here, you can see we have successfully set the file descriptor on Docker container:
This is all about setting ulimits or file descriptors on Docker containers.
Conclusion
To set the ulimits or file descriptor on the Docker container, first, create the Docker images by utilizing the Dockerfile instructions. After that, build the container and set the ulimits for the container using the “–ulimit” option along with the “docker run” command. To set the file descriptor, specify the “–ulimit” value as “nofile=soft-ulimit:hard-ulimit”. This write-up has demonstrated how to set the ulimit or file descriptor on the Docker container.