What are baseline expectations for the number of open file handles with Docker in WSL2

Hello,
I’m trying to track down some test failures I’m seeing with our app in WSL2 related to “Too many open files.”

I have Docker Desktop 4.13.1 running with no containers running.
I am running Windows 10 Pro Version 21H1 OS build 19043.2130.

I am running Debian in wsl2,

piro@Scott-PC:~$ uname -a
Linux Scott-PC 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022 x86_64 GNU/Linux
piro@Scott-PC:~$

When I run lsof I see there are around 400 open file handles,

piro@Scott-PC:~$ lsof 2>&1 |wc -l
436

And a lot are related to docker!

piro@Scott-PC:~$ lsof 2>&1 | grep docker |wc -l
320

A number of these are under /proc and have a Permission denied message after them.

What are the expected number of open file handles with no containers running?

Where do you get that message exactly?

I think you can get the limit by running the following in the WSL distribution:

sysctl fs.file-max

or

cat /proc/sys/fs/file-max

but that should be way bigger than 436

Those are related to the WSL integration. If you disable WSL integration, you will probably not see any Docker related process since Docker will run in its own WSL distribution even if you have integration.

Thanks for the reply!

lsof is reporting all the open file handles. I piped it into wc to count the number of lines. Currently with the system doing basically nothing there are 436 open file handles. Of these, docker has 320. I was asking if this was expected or perhaps something might be awry? It just seemed like a lot to me but I honestly was just asking out of curiosity.

ulimit -n defaults to 1024.

piro@Scott-PC:~$ cat /proc/sys/fs/file-max
5254554

Is it recommended to turn off that WSL integration? I thought it was the default in the Docker Desktop settings?

I had 88 without WSL integration and 156 with WSL integration, but I guess it depends on how you use Docker Desktop. Since I use Docker Desktop on my Mac, and I only use it on Windows to check how it works when someone asks about it, 320 could be normal. I don’t know. Since you wrote and also showed you didn’t have running containers, having 320 docker related open files seems indeed too many, but I am not sure about that. I don’t know enough about WSL integration.

If I use the file exploreron Windows to browse the filesystem of the WSL distribution I get more open files. If you fo example use Visual Studio Code to open a project on WSL’s filesystem, that could also increase the number of open files.

I don’t remember if it was default. I installed Docker Desktop for Windows a long time ago. I should probably reinstall it to see the current default settings.

If you really want to use the Docker client from your WSL distribution instead of PowerShell or Command Line, you definitely don’t want to disable it. If you don’t need that, you can safely disable it if it helps. It should not cause any problem, I just wanted to point out that you only see docker related output of lsof, because of WSL integration, but you will not see the files opened in the other distribution in which Docker daemon and your containers are actually running. If you get “Too many open files” error message, that is probably caused by open files in multiple WSL distributions together, including the distribution of Docker like “docker-desktop” and “docker-desktop-data”.

if you want to see the number of open files in the docker-desktop distribution, you run this command:

docker run --rm -it --pid host bash -c "lsof | wc -l"

I don’t know how you could see it in “docker-desktop-data”.