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

I have seen this issue solved for windows, but I am running macOS and was wondering how this can be solved.
I added the line vm.overcommit_memory = 1 to /etc/sysctl.conf and rebooted, yet I am still running into the error:

#WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can also cause failures without low memory condition, see vm.max_map_count growing steadily when vm.overcommit_memory is 2 · Issue #1328 · jemalloc/jemalloc · GitHub. To fix this issue add ‘vm.overcommit_memory = 1’ to /etc/sysctl.conf and then reboot or run the command ‘sysctl vm.overcommit_memory=1’ for this to take effect.

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.

1 Like