Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permission denied when mounting the redis data dir and enabling persistence #233

Closed
oreoluwa opened this issue Apr 5, 2020 · 5 comments
Closed
Labels
question Usability question, not directly related to an error with the image

Comments

@oreoluwa
Copy link

oreoluwa commented Apr 5, 2020

Hi,
For about a week now, I've been unable to mount the /data dir as I keep getting a permission error.
When the data dir isn't mounted, everything works perfectly.

$ docker run -it --rm -v $PWD/redis:/data redis redis-server --appendonly yes
1:C 05 Apr 2020 02:57:46.684 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 05 Apr 2020 02:57:46.684 # Redis version=5.0.8, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 05 Apr 2020 02:57:46.685 # Configuration loaded
1:M 05 Apr 2020 02:57:46.686 # Can't open the append-only file: Permission denied

The workaround I've been using is:

$ docker run -it --rm -v $PWD/redis:/data redis sh -c 'redis-server --appendonly yes'
7:C 05 Apr 2020 03:03:58.246 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
7:C 05 Apr 2020 03:03:58.246 # Redis version=5.0.8, bits=64, commit=00000000, modified=0, pid=7, just started
7:C 05 Apr 2020 03:03:58.247 # Configuration loaded
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 5.0.8 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 7
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

7:M 05 Apr 2020 03:03:58.255 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
7:M 05 Apr 2020 03:03:58.255 # Server initialized
7:M 05 Apr 2020 03:03:58.256 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
7:M 05 Apr 2020 03:03:58.388 * DB loaded from append only file: 0.132 seconds
7:M 05 Apr 2020 03:03:58.388 * Ready to accept connections

Environments:
Machine Macbook Pro (MacOS 10.15.4)
Docker Toolbox (with Virtualbox)
docker-machine version 0.16.1, build cce350d7
Client: Docker Engine - Community
Version: 19.03.1
API version: 1.40
Go version: go1.12.5
Git commit: 74b1e89
Built: Thu Jul 25 21:18:17 2019
OS/Arch: darwin/amd64
Experimental: true

Server: Docker Engine - Community
Engine:
Version: 19.03.5
API version: 1.40 (minimum version 1.12)
Go version: go1.12.12
Git commit: 633a0ea838
Built: Wed Nov 13 07:28:45 2019
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v1.2.10
GitCommit: b34a5c8af56e510852c35414db4c1f4fa6172339
runc:
Version: 1.0.0-rc8+dev
GitCommit: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
docker-init:
Version: 0.18.0
GitCommit: fec3683

@wglambert wglambert added the question Usability question, not directly related to an error with the image label Apr 6, 2020
@wglambert
Copy link

This comment #7 (comment) and the ones after it seem relevant

You might have a better time using Docker for Mac https://docs.docker.com/docker-for-mac/docker-toolbox/
Instead of the legacy Docker Toolbox https://docs.docker.com/toolbox/overview/

I think an easy solution would be to use Docker's named volumes, similar to this issue MariaDB/mariadb-docker#278 (comment)

@hrvylein
Copy link

hrvylein commented Apr 6, 2020

same issue hier on synology docker. unable to run redis unless I set the mounted volume to be read/writable by everyone. mounted volume gets owner set to 999 (which I assume is the user redis inside of the container). I am doing a -v /edsm/redis:/data to make data persistent.

chown -R 999:999 and setting UID and/or GID in environment settings is not working. Everytime I get a permission error. Postgres works without these hickups. Any workaround?

Synology Docker Version: 18.09.0-0506
DSM 6.2.2-24922 Update 4

redis version 5.0.8 (f3c7eac42f433326a8d981b50dba0169fdfaf46abb23fcda2f933a7552ee4ed7)

@yosifkit
Copy link
Contributor

yosifkit commented Apr 9, 2020

Since #48, you can just use --user on the docker run to run it as a user/group other than root that can already write to the directory that you are giving it to use. Otherwise it will attempt to chown all files/folders not owned by redis (uid 999 in the container) to redis and then drop from root to the redis user:

https://github.com/docker-library/redis/blob/886e71565ce748fd265c262d782b6c22c7540173/5.0/docker-entrypoint.sh#L11-L14


(not recommended, but if you really want to run as root, then skip the entrypoint script: ie docker run -d --entrypoint redis-server redis:5 --appendonly yes)

@yosifkit yosifkit closed this as completed Apr 9, 2020
@hrvylein
Copy link

Not working for me. Starting it with --user 1045 (id redisuser on host) gives permission error. Starting with --user redisuser gives invalid argument error on config line 6.

@spashii
Copy link

spashii commented Sep 18, 2024

doing chmod -R 777 to the directory fixed my problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Usability question, not directly related to an error with the image
Projects
None yet
Development

No branches or pull requests

5 participants