Redis WARNING Memory overcommit must be enabled
Asked Answered
A

2

12

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

Anethole answered 3/8, 2023 at 18:42 Comment(4)
"To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot" – did you try what the error message is telling you?Linotype
my issue is where do i update this /etc/sysctl.conf from docker?Anethole
This is also happening to a Docker setup of mine. Seems to make little sense to me, to fix this for a Docker deployment.Eridanus
Are you sure this problem is in any way related to Java or node.js?Tena
N
8

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.

Newfashioned answered 23/10, 2023 at 13:40 Comment(0)
I
0

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}
    ....
Ionize answered 17/2 at 11:19 Comment(1)
yes, this blog explains it well.Retch

© 2022 - 2024 — McMap. All rights reserved.