Redis warns that vm.overcommit_memory must be enabled
WARNING Memory overcommit must be enabledShort answer
This is a Linux kernel setting, vm.overcommit_memory, and a container shares the host's kernel. Set it to 1 on the Docker host with sysctl, and add it to /etc/sysctl.conf so it survives a reboot. Putting it in docker run --sysctl or compose does not work because Docker only allows namespaced sysctls.
Fix it fast
1Find out which cause you have
Read the current value on the Docker host, not inside the container. 0 is the default and is what triggers the warning.
sysctl vm.overcommit_memory2Match what you see, then jump to its fix
- 1
The warning appears in docker logs every time the container startsThe host kernel has the default value 0Fix - 2
The warning returns after the server restartsThe setting was applied once and lost after a rebootFix - 3
You added sysctls: vm.overcommit_memory to compose, or passed --sysctl to docker run, and the warning is still there or the container will not startYou tried to set it from the container or from docker runFix
- 1
What does the error look like?
WARNING Memory overcommit must be enabledBackground saving fails with a fork() error
Cause 1 of 3
The host kernel has the default value 0
1Check
Redis forks a child to save to disk. With the setting at 0, Linux fails the fork unless it has as much free memory as the full copy would need, even though copy-on-write means it rarely does. Redis asks for 1 so the kernel allows the fork.
cat /proc/sys/vm/overcommit_memory2Fix
Set the value to 1 on the host. This takes effect at once and lasts until the next reboot.
sudo sysctl vm.overcommit_memory=13Verify
Restart the container; the warning should be gone.
docker restart my-redis
docker logs --tail 20 my-redisConfirmed by redis.io
Cause 2 of 3
The setting was applied once and lost after a reboot
1Check
A sysctl command only changes the running kernel. The Redis administration guide says to add the line to /etc/sysctl.conf so it is applied at boot.
grep -r overcommit /etc/sysctl.conf /etc/sysctl.d/ 2>/dev/null2Fix
Add the line to /etc/sysctl.conf and activate it.
echo 'vm.overcommit_memory = 1' | sudo tee -a /etc/sysctl.conf
sudo sysctl vm.overcommit_memory=13Verify
Reboot the host and read the value again.
sysctl vm.overcommit_memoryConfirmed by redis.io
Cause 3 of 3
You tried to set it from the container or from docker run
1Check
Docker only allows sysctls that are namespaced: some kernel.* IPC values and the net.* ones. vm.overcommit_memory is not one of them, because changing it would change the host.
docker run --rm --sysctl vm.overcommit_memory=1 redis:latest true2Fix
Remove the sysctl from your compose or run command and set the value on the host as in the first cause.
# remove this from compose.yaml
# sysctls:
# vm.overcommit_memory: 13Verify
Run docker compose config and confirm no sysctls line remains for vm.overcommit_memory.
docker compose config | grep -n overcommit || echo noneConfirmed by docs.docker.com
How do I stop it coming back?
- Put vm.overcommit_memory = 1 into the server provisioning script so every new Docker host has it.
- Set maxmemory on Redis so it reports errors instead of growing until the host runs out of memory.
- Document that the setting is host-wide: it also applies to every other process on that machine.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fixServers
sam local fails: Running AWS SAM projects locally requires Docker
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
sam local start-api and sam local invoke run your function inside a Docker container, so SAM stops if it cannot talk to Docker.
3 causes, each with a fixServers
dnf fails to download repo metadata in a CentOS 8 Docker build
The same Dockerfile built fine before 2022
CentOS Linux 8 reached end of life on 31 December 2021 and its content left the mirrors.
2 causes, each with a fixServers
pip install confluent-kafka fails because librdkafka/rdkafka.h is missing
pip stops while building confluent-kafka from source
The error means pip is compiling confluent-kafka from source, and the compiler cannot find the librdkafka C headers.
3 causes, each with a fixServers
Cypress says the npm package is installed but the binary is missing
Cypress binary is missing after npm install in CI or in a Docker build
The npm package is only a launcher.
3 causes, each with a fixServers
A dev container port does not open in the browser when Docker runs on a remote host
If your application only accepts calls from localhost, it will reject connections from published ports
Three things usually break it: the app listens only on localhost inside the container, so published ports are rejected; you open the container port instead of the mapped localhost port VS Code shows; or you changed appPort or a Compose ports list and did not rebuild.
3 causes, each with a fix