如果我使用默认的 *redis docker图像 * 配置docker构成如下:
redis-storage:
image: redis:7.0
container_name: 'redis-storage'
command: ["redis-server", "--save", "1200", "32", "--loglevel", "warning"]
volumes:
- redis-storage-data:/data
如果至少有32个更改,则它会正常启动并每20分钟写入磁盘。
但是如果我使用相同的command
和image: redis/redis-stack-server:latest
,它看起来启动正常,但它实际上进入了保护模式,变得不可访问。
允许更改默认的保存到磁盘参数的docker-compose格式的正确command
是什么?
(Also已尝试其他语法:(一个月三个月一次)
1条答案
按热度按时间5vf7fwbs1#
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)