The Problem ContextWhile managing a Redis instance, it is common to change configurations on the fly using the CONFIG SET command. For example, you might increase the maxmemory or change the appendonly status without wanting to restart the service. To make these changes permanent, the standard practice is to run:
127.0.0.1:6379> CONFIG REWRITE
However, you might encounter this specific error message:
(error) ERR The server is running without a config file
This happens because Redis was started as a bare process without a pointer to a physical redis.conf file. If Redis doesn't know where its configuration file lives, it cannot rewrite it to save your changes.
Why this error occursRedis can start in two ways. The first is by specifying a configuration file path as an argument. The second is by running the binary alone, which causes Redis to use built-in default values. If you use the latter method, Redis operates entirely in memory regarding its configuration. When you trigger CONFIG REWRITE, the engine looks for the file path it was initialized with. Finding none, it throws the error because there is no target file to update.
Common scenarios leading to this:
- Starting the server manually via
redis-serverinstead ofredis-server /path/to/redis.conf.- Docker containers where the command is justredis-serverand the config isn't mapped or specified.- Systemd unit files that are missing the configuration file argument in theExecStartdirective.## Debugging the SetupBefore applying a fix, confirm how your Redis process was started. On a Linux system, usepsto inspect the running process:
ps aux | grep redis-server
If the output looks like this, you have confirmed the issue:
redis 1234 0.1 0.5 150000 10000 ? Ssl 10:00 0:01 /usr/bin/redis-server *:6379
Notice that there is no file path after the port. A correctly configured instance should look like this:
redis 1234 0.1 0.5 150000 10000 ? Ssl 10:00 0:01 /usr/bin/redis-server /etc/redis/redis.conf
The Solution### Method 1: Restarting with a Config File (Recommended)The most robust fix is to ensure Redis starts with a configuration file. If you don't have one, you can download the default redis.conf for your version from the official Redis GitHub repository.
- Create or locate your config file (usually at
/etc/redis/redis.conf).- Stop the current Redis instance:redis-cli shutdown- Start Redis while explicitly pointing to the config file:redis-server /etc/redis/redis.confIf you are using Systemd, check your service file at/etc/systemd/system/redis.serviceor/lib/systemd/system/redis.service. Ensure theExecStartline includes the path:
ExecStart=/usr/bin/redis-server /etc/redis/redis.conf
Method 2: Fixing Docker EnvironmentsIn Docker, this error often occurs because the container starts with the default entrypoint. To fix this, you must mount a local config file into the container and tell Redis to use it in the docker-compose.yml or docker run command.
Example docker-compose.yml snippet:
services:
redis:
image: redis:latest
volumes:
- ./redis.conf:/usr/local/etc/redis/redis.conf
command: ["redis-server", "/usr/local/etc/redis/redis.conf"]
Method 3: The "No-Restart" WorkaroundIf you cannot afford downtime to restart Redis but desperately need to save your current runtime configuration, you can manually create a file from the current state. This is a bit of a hack but works in emergencies.
- Connect to Redis and get all current configs:
redis-cli CONFIG GET * > current_config.txt- This output isn't in theredis.confformat (it's key-value pairs on new lines). You'll need to reformat it manually or via a script intokey valueformat.- Once you've created a validredis.conf, you must still restart Redis with that file to enableCONFIG REWRITEfor future use. There is no way to "attach" a config file to a running Redis process without a restart.## VerificationOnce you have restarted Redis with the configuration file path, verify that the fix works: - Connect via
redis-cli.- Change a dummy parameter:127.0.0.1:6379> CONFIG SET loglevel notice- Execute the rewrite:127.0.0.1:6379> CONFIG REWRITEIf it returnsOK, the fix is successful. You can also check the timestamp of yourredis.conffile on the filesystem; it should reflect the time you ran the command.

