If I use the default redis docker image configured with docker compose as such:
redis-storage:
image: redis:7.0
container_name: 'redis-storage'
command: ["redis-server", "--save", "1200", "32", "--loglevel", "warning"]
volumes:
- redis-storage-data:/data
it starts up fine and writes to disk every 20 minutes if at least 32 changes.
But if I use the same command
with image: redis/redis-stack-server:latest
it appears to start okay, but it really goes into protected mode and becomes inaccessible. Commenting out the command, all works fine.
What is the correct command
in docker-compose format that will allows altering the default save-to-disk parameters?
(Also tried alternative syntax: command: redis-server --save 1200 32
)
Working solution for
docker-compose schema '3.8'
:Not easy to find a clear, non-conflicting example. And something of an historical bug.
For
redis-stack-server
(when not using a localredis-stack.conf
file mounted to the container) configuration for the underlying redis can be passed in via theREDIS_ARGS
environment variable instead of directly to the command. (There are also environment vars for the stack modules, such asREDISJSON_ARGS
, etc.However 'save' is particularly fussy. It expects two arguments
(seconds, changes)
but most configuration parameters expect one. Some forms of quoting the arguments would make it look like one argument, and the underlying argument parser would either be ignored or report 'wrong number of arguments' and put the server into protected mode.For
save
, you can also specify several conditionals. For example, the default is:save 3600 1 300 100 60 10000
(Save after 1hr if 1 write, after 5min if 100 writes, after 60 sec if 10000 writes)
For the original
redis
container, you can specify this in docker-compose as command line arguments using the following format:However, the underlying argument parsing logic creates a problem for
redis-stack
Both of these formats will be parsed incorrectly:The correct syntax is obscure:
If you
docker exec
into the running container and invokeredis-cli CONFIG GET save
it will return:There is also an alternative compose syntax example in the redis developer docs
but compose schema 3.8 will complain (the example uses schema 3.9)