大网数据广告活动
服务器运维问答

Redis inside Docker Compose Permission Denied for RDB file Crontab

· 52CE 我爱测

Hi I have following docker-compose.yaml file. version: "3.9" volumes: local_postgres_data2: {} local_postgres_data_backups2: {} services: postgres: image: postgres container_name: angel-postgres restart: always volumes: - local_p…

问题原文

原帖链接 · Mudassar Hashmi · CC BY-SA 4.0

Hi I have following docker-compose.yaml file.

version: "3.9"

volumes:
  local_postgres_data2: {}
  local_postgres_data_backups2: {}

services:
  postgres:
    image: postgres
    container_name: angel-postgres
    restart: always
    volumes:
      - local_postgres_data2:/var/lib/postgresql/data:Z
      - local_postgres_data_backups2:/backups:z
    environment:
      POSTGRES_DB: angel-agility
      POSTGRES_HOST: localhost
      POSTGRES_USER: angel-user
      POSTGRES_PASSWORD: angel123
    ports:
      - "5432:5432"

  redis:
    container_name: angel-redis
    image: redis:latest
    ports:
      - '6379:6379'
    restart: unless-stopped

When I run docker-compose up I get error in logs for Redis:

2276:C 29 Mar 2022 20:32:52.005 # Failed opening the RDB file crontab (in server root dir /etc) for saving: Permission denied
1:M 29 Mar 2022 20:32:52.105 # Background saving error

I tried all the solutions on different platforms but couldn't make Redis work. A clue or direction make it work will be highly appreciated.

Also a little brief about the problem in detail why its happening would also be great help for readers and me. Looking forward.

已采纳解答

原帖链接 · posixpascal · CC BY-SA 4.0

I've encountered the same issue running a redis container on AWS ECS in a similar fashion.

I connected to the redis container and executed:

redis-cli
> CONFIG GET dbfilename

It returned the following:

1) "dbfilename"
2) "crontab"

I tried to remove the crontab file by running config set dbfilename "dbfilename" which failed with an error.

I've found out that redis was running without a config file. So I added an extra volume for redis and created the file using touch data/redis/config/redis.conf.

Then I've changed my compose file accordingly:

  redis:
    container_name: redis
    command: redis-server /conf/redis.conf
    image: redis:latest
    volumes:
       - "./data/redis/data:/data"
       - "./data/redis/config:/conf"
    ports:
      - '6379:6379'
    restart: unless-stopped

After rebooting the container I've run the same CONFIG GET dbfilename command but this time the crontab file was missing.

Everything worked after that :)

Also make sure that you set a password for your redis server if it's accessible from the internet.

    docker run -d \
    -h redis \
    -e REDIS_PASSWORD=your-super-secure-password \
    -v redis-data:/data \
    -v redis-config:/conf \
    -p 6379:6379 \
    --name redis \
    --restart always \
    redis:latest /bin/sh -c 'redis-server /conf/redis.conf --appendonly yes --requirepass ${REDIS_PASSWORD}'

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2022-03-29)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。