Permission denied issue when persist redis data inside docker container

Viewed 903

I want to create a redis container and need to mount the rdp and log file inside the container to host machine. I have a docker-compose file as below,

version: '2'
services:
  redis:
    image: xxxx/redis
    container_name: redis
    restart: unless-stopped
    volumes:
       - /redis/data:/var/lib/redis
       - /redis/log:/var/log/redis
    ports:
      - "6379:6379"

If it mount the volume as above, redis is not running inside the container and sometimes i am getting unable to save rdb file due to permission denied error. If i create a container without volume mount, everything is working fine.

After doing some search i found that the permission inside redis for /var/lib/redis and /var/log/redis folder is redis:redis but the permission for the mounted volume in host machine is root:root. I cant change the permission as redis in host machine because the redis user will not be available. If i change the permission as root:root inside container, rdp files are not getting saved.

Can anyone please suggest how to fix this issue.?

0 Answers
Related