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
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.
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}
....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With