用于redis-stack-server持久性的Docker-Compose命令

wqsoz72f  于 2022-12-11  发布在  Redis
关注(0)|答案(1)|浏览(443)

如果我使用默认的 *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分钟写入磁盘。
但是如果我使用相同的commandimage: redis/redis-stack-server:latest,它看起来启动正常,但它实际上进入了保护模式,变得不可访问。
允许更改默认的保存到磁盘参数的docker-compose格式的正确command是什么?
(Also已尝试其他语法:(一个月三个月一次)

5vf7fwbs

5vf7fwbs1#

Working solution for docker-compose schema '3.8' :

redis-stack-svc:
  image: redis/redis-stack-server:latest
  # use REDIS_ARGS for redis-stack-server instead of command arguments
  environment:
    - REDIS_ARGS=--save 1200 32
  volumes:
    - my-redis-data:/data

Not easy to find a clear, non-conflicting example. And something of an historical bug.
For redis-stack-server (when not using a local redis-stack.conf file mounted to the container) configuration for the underlying redis can be passed in via the REDIS_ARGS environment variable instead of directly to the command. (There are also environment vars for the stack modules, such as REDISJSON_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:

redis-storage:
  image: redis:7.0
  command: ["redis-server", "--save", "3600", "1", "300", "100", "60", "10000"]
  volumes:
    - my-redis-data:/data

However, the underlying argument parsing logic creates a problem for redis-stack Both of these formats will be parsed incorrectly:

# (valid syntax but ignored...'save' is actually set to 'nil')
  environment: 
    - REDIS_ARGS=--save 3600 1 300 100 60 10000
  
  # ('invalid number of arguments', server not started) 
  environment:
    - REDIS_ARGS="--save 3600 1 300 100 60 10000"

The correct syntax is obscure:

# (using non-default values here to validate the behavior) 
  environment:
    - REDIS_ARGS=--save 3602 1 --save 302 100 --save 62 10000

If you docker exec into the running container and invoke redis-cli CONFIG GET save it will return:

root@f45860:/data# redis-cli CONFIG GET save
1) "save"
2) "3602 1 302 100 62 10000"

There is also an alternative compose syntax example in the redis developer docs

environment:
    - REDIS_ARGS:--save 20 1

but compose schema 3.8 will complain (the example uses schema 3.9)

相关问题