Redis配置持续自动重置,未重启Docker容器仍恢复原值求助
Let's break down possible reasons why your Redis dir setting keeps reverting to /etc/crontabs even without restarting the container, and how to fix them:
1. Missing CONFIG REWRITE After CONFIG SET
When you run CONFIG SET dir "/data", this only modifies the running in-memory configuration of Redis—it doesn’t save the change to your actual config file. If any process triggers Redis to reload its config file (like a SIGHUP signal sent to the Redis process), it will fall back to the original value from the file.
To lock in the change:
- Right after running
CONFIG SET dir "/data", execute this command to write the running config back to your Redis config file:redis-cli CONFIG REWRITE
This ensures future config reloads will use your new dir value instead of the old one.
2. Check for Automated Crontab Scripts
Since the reverted path is /etc/crontabs, there’s a strong chance a scheduled task in your container is overriding the Redis config. Here’s how to investigate:
- Enter your Redis container to inspect crontabs:
docker exec -it <your-redis-container-id> /bin/bash - List all active cron jobs:
crontab -l - Check the
/etc/crontabsdirectory for scripts that might runredis-clicommands to reset thedirsetting:ls -la /etc/crontabs cat /etc/crontabs/*
If you find a script that’s modifying the Redis config, either update it to stop changing the dir value or remove the cron job entirely.
3. Verify Docker Volume Mounts and Config File Integrity
If you’re starting the container with a custom config file, double-check these details:
- Ensure your custom config file is correctly mounted into the container (review your
docker runcommand ordocker-compose.ymlvolume settings). A broken mount could mean Redis is using a default config file instead of your custom one. - Confirm the
dirdirective in your config file is set to/data(not/etc/crontabs). Check the file content inside the container:cat /path/to/your/redis.conf | grep "dir " - Make sure the Redis process has write permissions to the config file (so
CONFIG REWRITEcan work properly). Check permissions with:ls -la /path/to/your/redis.conf
4. Rule Out External Config Sync Tools
If your Docker environment uses tools like Consul, etcd, or a custom configuration sync service, these might be periodically pushing a default config to Redis. Verify if any such tools are running alongside your container and adjust their settings to preserve your dir configuration.
内容的提问来源于stack exchange,提问作者sukidesuaoi

