有几个类似的问题,例如:
Redis已配置保存RDB快照,但当前无法持久化到磁盘-Ubuntu服务器
MISCONF Redis已配置保存RDB快照,但当前无法持久化到磁盘。禁用可能修改数据集的命令
但这些都不能解决我的问题。
问题是我在docker-compose中运行我的redis,而且就是不知道如何在docker-compose启动时解决这个问题。
Redis文档说这是解决方法:
echo 1 > /proc/sys/vm/overcommit_memory
当Redis安装在docker外部时,这个方法是有效的。但是我该如何在docker-compose中运行此命令呢?
我尝试了以下方法:
1)添加命令:
services:
cache:
image: redis:5-alpine
command: ["echo", "1", ">", "/proc/sys/vm/overcommit_memory", "&&", "redis-server"]
ports:
- ${COMPOSE_CACHE_PORT:-6379}:6379
volumes:
- cache:/data
这个不起作用:
docker-compose up
Recreating constructor_cache_1 ... done
Attaching to constructor_cache_1
cache_1 | 1 > /proc/sys/vm/overcommit_memory && redis-server
constructor_cache_1 exited with code 0
2) 挂载/proc/sys/vm/
目录。
这个失败了:事实证明我无法挂载到/proc/目录。
3) 覆盖入口点:
custom-entrypoint.sh:
#!/bin/sh
set -e
echo 1 > /proc/sys/vm/overcommit_memory
# first arg is `-f` or `--some-option`
# or first arg is `something.conf`
if [ "${1#-}" != "$1" ] || [ "${1%.conf}" != "$1" ]; then
set -- redis-server "$@"
fi
# allow the container to be started with `--user`
if [ "$1" = 'redis-server' -a "$(id -u)" = '0' ]; then
find . \! -user redis -exec chown redis '{}' +
exec su-exec redis "$0" "$@"
fi
exec "$@"
docker-compose.yml:
services:
cache:
image: redis:5-alpine
ports:
- ${COMPOSE_CACHE_PORT:-6379}:6379
volumes:
- cache:/data
- ./.cache/custom-entrypoint.sh:/usr/local/bin/custom-entrypoint.sh
entrypoint: /usr/local/bin/custom-entrypoint.sh
这个也不起作用。
如何修复这个问题?