Thank you for the C++ code. I almost never write C++ code so it helps a lot when I get a working code to try. Using that I did some research to understand these parameters a little bit better.
It looks like you were right. I knew SC_OPEN_MAX
was similar to the kernel variable fs.file-max
and I assumed they were the same. It seems I was wrong. In fact SC_OPEN_MAX
is the value that you can also get by using ulimit -n
. It is a process level setting. Since a container is an isolated process, you can get a different value in a container and on the host.
In my test VM I tried this to demonstrate:
docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp gcc:4.9 g++ -o myapp myapp.c
docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp gcc:4.9 ./myapp
# output: 1048576
docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp gcc:4.9 bash -c 'ulimit -n'
# output: 1048576
./myapp
# output: 1024
ulimit -n
# output: 1024
The maximum value of the open files at process level can be changed by using ulimit and the docker run command also has an “ulimit” parameter to change this value.
docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp --ulimit nofile=300:300 gcc:4.9 ./myapp
# output: 300
docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp --ulimit nofile=300:300 gcc:4.9 bash -c 'ulimit -n'
# output: 300
If you want to change the default value, the Docker daemon has paramaters to do that. Either by using the dockerd command or by using the following config file at /etc/docker/daemon.json
and restarting the docker daemon.
{
"default-ulimits": {
"nofile": {
"Hard": 64000,
"Name": "nofile",
"Soft": 64000
}
}
}
After this you would get this:
docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp gcc:4.9 ./myapp
# output: 64000
docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp gcc:4.9 bash -c 'ulimit -n'
# output: 64000
I am not sure why it is dfferent on one of your machines. I can only guess like
- Even though you has the same version number of the Docker engine on the two hosts, you could have installed Docker differently. For example on one host you used snap, on another you followed the official documentation, or you could have also installed Docker from Ubuntu’s own repository, but in these cases the version number should be different.
- It is also possible that on one host you ae using rootful Docker (installed system-wide) and on the other you have rootless Docker (available only for one user) so these daemons can have different values. If you acidentally change the context you use a different daemon
If anything is installed differently, different updates can be applied or at least not the same time, so one could lose the modified setting after an upgrade while the other doesn’t.
The second is the same as on my machine. So the first might have a different daemon configuration.
What you can try
- Check
/etc/docker/daemon.json
- Check the parameters of dockerd
sytemctl status dockerd
- Check the output of
docker info
anddocker version
which can give you some idea about the differences if there is any. (You have probably done that already)
- Check the docker context
docker context ls
But this can also be seen in the output of docker info
I hope this helps more than my previous answer 