与此类似的问题还有很多,例如:
Redis配置为保存RDB快照,但目前无法持久保存在磁盘上 - Ubuntu Server
MISCONF Redis 配置为保存 RDB 快照,但目前无法保留在磁盘上。可能修改数据集的命令被禁用
但这些都不能解决我的问题。
问题是我在 docker-compose 中运行我的 redis,并且无法理解如何在 docker-compose 启动时修复此问题。
The 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)覆盖入口点:
自定义入口点.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
这也行不通。
如何解决这个问题?