有几个与此问题类似的问题,例如:

Redis is configured to save RDB snapshots, but it is currently not able to persist on disk - Ubuntu Server

MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled

但是这些都不能解决我的问题。

问题是我在docker-compose中运行我的redis,只是无法理解如何在docker-compose启动时解决此问题。

redis docs说这是解决方法:



当Redis安装在docker之外时,这可以工作。但是如何使用docker-compose运行此命令?

我尝试了以下方法:

1)添加命令:

services:
  cache:
    image: redis:5-alpine
    command: ["echo", "1", ">", "/proc/sys/vm/overcommit_memory", "&&", "redis-server"]
    ports:
      - ${COMPOSE_CACHE_PORT:-6379}:6379
    volumes:
      - cache:/data

这不起作用:
 docker-compose up
Recreating constructor_cache_1 ... done
Attaching to constructor_cache_1
cache_1  | 1 > /proc/sys/vm/overcommit_memory && redis-server
constructor_cache_1 exited with code 0


2)挂载/proc/sys/vm/目录。

失败:证明我无法挂载到/ proc /目录。

3)覆盖入口点:

custom-entrypoint.sh:

#!/bin/sh
set -e

echo 1 > /proc/sys/vm/overcommit_memory


# first arg is `-f` or `--some-option`
# or first arg is `something.conf`
if [ "${1#-}" != "$1" ] || [ "${1%.conf}" != "$1" ]; then
    set -- redis-server "$@"
fi

# allow the container to be started with `--user`
if [ "$1" = 'redis-server' -a "$(id -u)" = '0' ]; then
    find . \! -user redis -exec chown redis '{}' +
    exec su-exec redis "$0" "$@"
fi


exec "$@"


docker-compose.yml:
services:
  cache:
    image: redis:5-alpine
    ports:
      - ${COMPOSE_CACHE_PORT:-6379}:6379
    volumes:
      - cache:/data
      - ./.cache/custom-entrypoint.sh:/usr/local/bin/custom-entrypoint.sh
    entrypoint: /usr/local/bin/custom-entrypoint.sh

这也行不通。

如何解决这个问题?

最佳答案

TL; DR 您的redis不安全

更新:
使用expose而不是ports,以便该服务仅可用于链接的服务



原始答案:

长答案:

这可能是由于不安全的redis-server实例所致。 Docker容器中的默认Redis镜像是不安全的。

我只用redis就可以连接到我的Web服务器上的redis-cli -h <my-server-ip>
为了解决这个问题,我经历了this DigitalOcean article和许多其他事件,并能够关闭端口。

  • 您可以从here中选择默认的redis.conf
  • 然后将您的docker-compose redis部分更新为(相应地更新文件路径)
  • redis:
        restart: unless-stopped
        image: redis:6.0-alpine
        command: redis-server /usr/local/etc/redis/redis.conf
        env_file:
          - app/.env
        volumes:
          - redis:/data
          - ./app/conf/redis.conf:/usr/local/etc/redis/redis.conf
        ports:
          - "6379:6379"
    
    redis.confcommandvolumes的路径应匹配
  • 根据需要重建redis或所有服务
  • 尝试使用redis-cli -h <my-server-ip>进行验证(已停止为我工作)
  • 关于docker - docker:MISCONF Redis配置为保存RDB快照,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60743175/

    10-16 16:25
    查看更多