How to set the vm.overcommit_memory parameter when running docker desktop on macOS?

I don’t know where you edited the config file, but you shouldn’t change any file in the VM even if it works and I thought the filesystem was read-only. You probably found that on Windows, you could run the sysctl command in a WSL2 distribution, but you can also run a privileged container that can change kernel parameters and that works on every platform:

docker run --rm -it --privileged ubuntu:22.04 sysctl vm.overcommit_memory=1

Then you can test it:

docker run --rm -it ubuntu:22.04 sysctl vm.overcommit_memory

You can’t make it permanent, but you can run it manually when you start Docker Desktop or use “depend_on” in a compose file to run this container before the container that requires it. You could also run a container that checks the value in a loop and corrects it if needed. Or just set it in a loop.