Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis WARNING Memory overcommit must be enabled

I'm running my redis server on a docker container hosted on my local windows machine, but i am unable to store data because of this warning

WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. 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.

is there a way i can enable this?

version: '3'
services:
  redis:
    image: "redis"
    ports:
      - "6379:6379"
    networks:
      - my-service

networks:
  my-service:
    external: true

like image 776
watch dog Avatar asked Nov 30 '25 06:11

watch dog


2 Answers

First of all, it has nothing to do with the Redis image or container itself and there isn't any direct way to resolve it through the docker-compose or the docker run command. It's merely related to the host OS which in Windows case is the Linux hypervisor which docker runs on top of it.

If you use the WSL2 backend like me to run docker on your Windows, you can change it temporarily by simply starting a WSL distribution, and running:

sudo sysctl -w vm.overcommit_memory=1

It will not be persistent by the way. Unfortunately dealing with this issue requires a good knowledge of Linux to work against user permissions, strange access denies, package managers, etc and for me, coming from the Windows background, it was a tough task to dig into this issue any further.

like image 132
Farshad Davoudi Avatar answered Dec 01 '25 23:12

Farshad Davoudi


I solved it with added one line to default entrypoint.sh

It's work ONLY if redis command args moved to environment variable REDIS_ARGS

#!/usr/bin/dumb-init /bin/sh
sysctl vm.overcommit_memory=1

And start container as privileged mode

Here is Dockerfile

FROM redis/redis-stack-server:7.2.0-v8

COPY entrypoint.sh /entrypoint.sh

RUN chmod +x entrypoint.sh

CMD ["/entrypoint.sh"]

Build new image cmd

sudo docker buildx build -t redis/redis-stack-server:7.2.0-v8-fixed .

And now we can use fixed image in e.g. compose.yml file

Here is my compose.yml file

services:
  redis:
    image: redis/redis-stack-server:7.2.0-v8-fixed # sysctl vm.overcommit_memory=1
    container_name: redis
    hostname: redis
    restart: unless-stopped
    network_mode: host
    privileged: true
    environment:
      REDIS_ARGS: ${REDIS_ARGS}
      REDISCLI_AUTH: ${REDIS_PASSWORD}
    ....
like image 32
1XTR Avatar answered Dec 02 '25 00:12

1XTR



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!