Search code examples
linuxdockerredisdockerfileredhat

Docker Redis start with persistent storage using -v gives error (chown: changing ownership of '.': Permission denied)


I'm using following system version/spec for the docker-redis setup using default redis.conf.

Redhat version: 7.6 (Red Hat Enterprise Linux Server)
Redis Version: 5.0.4
Docker Version:  1.13.1, build b2f74b2/1.13.1

When I run following command it's working perfectly fine.

sudo docker run -d -v $PWD/redis.conf:/usr/local/etc/redis/redis.conf --name redis-persistance --net tyk -p 7070:6379 redis redis-server /usr/local/etc/redis/redis.conf --appendonly yes

I need to get redis data (which is in /data inside the container) to the host directory (/usr/local/etc/redis/data) (-v $PWD/data:/data). So when I run following command I'm getting the below error. Note $PWD = /usr/local/etc/redis/

sudo docker run -d -v $PWD/redis.conf:/usr/local/etc/redis/redis.conf -v $PWD/data:/data --name redis-persistance --net tyk -p 7070:6379 redis redis-server /usr/local/etc/redis/redis.conf --appendonly yes

Error in docker logs:

journal: chown: changing ownership of '.': Permission denied
level=warning msg="05ce842f052e28566aed0e2eab32281138462cead771033790266ae145fce116 cleanup: failed to unmount secrets: invalid argument"

Also I tried changing the ownership of the data folder in the host to following as well. chown redis:redis data

drwxrwxrwx. 2 redis redis     6 May  3 07:11 data

Can someone help me out on this. Thanks.


Solution

  • First create a volume:

    docker volume create redis_data
    

    Check the volume is created (note the Mountpoint):

    docker volume inspect redis_data
    

    Then use this volume to start your container:

    sudo docker run -d -v $PWD/redis.conf:/usr/local/etc/redis/redis.conf -v redis_data:/data --name redis-persistance --net tyk -p 7070:6379 redis redis-server /usr/local/etc/redis/redis.conf --appendonly yes
    

    You can then check the contents of the "Mountpoint" that should be the redis data.