无法在docker中启动redis sentinel容器

zsohkypk  于 2021-06-09  发布在  Redis
关注(0)|答案(1)|浏览(560)

我试图在docker上设置redis sentinel,但sentinel容器没有启动。我有一个主人和一个奴隶,还有一个哨兵。
我使用的是ec2ubuntu示例(t2micro),我在那里安装了docker。
这是docker-compose.yaml

version: '3.5'

services:
  redis-master:
    container_name: "redis-master"
    image: redis
    ports:
      - "6379:6379"
    command: "redis-server /usr/local/etc/redis/redis.conf"
    volumes:
      - "./data/master:/data/"
      - "./master.conf:/usr/local/etc/redis/redis.conf"
    sysctls:
       - net.core.somaxconn=512
  redis-slave:
    container_name: "redis-slave"
    image: redis
    ports:
      - "6380:6379"
    command: "redis-server /usr/local/etc/redis/slave.conf"
    volumes:
      - "./data/slave:/data/"
      - "./slave.conf:/usr/local/etc/redis/slave.conf"
    sysctls:
       - net.core.somaxconn=512
  redis-sentinel:
    container_name: "redis-sentinel"
    image: redis
    ports:
      - "26379:26379"
    command: "redis-server /usr/local/etc/redis/sentinel.conf --sentinel"
    volumes:
      - "./sentinel.conf:/usr/local/etc/redis/sentinel.conf"
    sysctls:
       - net.core.somaxconn=512
    depends_on:
      - redis-master
      - redis-slave

开始后,我得到下面的错误和哨兵容器被杀死
sentinel配置文件/usr/local/etc/redis/sentinel.conf不可写:权限被拒绝。正在退出。。。

pobjuy32

pobjuy321#

redis在启动时使用redis用户,因此您可以

chown redis:redis /etc/redis/sentinel.conf

在您的redis sentinel dockerfile中,或者如果您只想使用compose文件,您可以尝试

command: bash -c "
    chown redis:redis /etc/redis/sentinel.conf
    && redis-server /usr/local/etc/redis/sentinel.conf --sentinel
  "

相关问题