docker-library / official-images

Primary source of truth for the Docker "Official Images" program
https://hub.docker.com/u/library
Apache License 2.0
6.51k stars 2.36k forks source link

Redis configuration bind mount permissions #858

Closed mut3 closed 9 years ago

mut3 commented 9 years ago

On the Redis dockerhub page, this line is given as a means of using a host machine stored configuration file as the redis config at run.

# docker run -v /myredis/conf/redis.conf:/usr/local/etc/redis/redis.conf --name myredis redis /usr/local/etc/redis/redis.conf

however if i run

# docker run  -v /redis/conf/redis1.conf:/usr/local/etc/redis/redis.conf redis /usr/local/etc/redis/redis.conf

i get

/entrypoint.sh: line 9: /usr/local/etc/redis/redis.conf: Permission denied

if I run

# docker run  -v /redis/conf/redis1.conf:/usr/local/etc/redis/redis.conf redis 

a default configured redis container launches perfectly, but i want to use my configuration file without writing my own Dockerfile

CentOS 7 Docker 1.6.2 redis:latest

I did a bunch of troubleshooting and hacked around to get it working, Ill document that below to leave a clear division between problem and workaround/hack.

mut3 commented 9 years ago

I had previously had issues bind-mounting other containers due to SELinux, but I had expected that and had already executed

# chcon -Rt svirt_sandbox_file_t /redis/

on my local machine. I confirmed that this was not a SELinux caused issue with

# setenforce 0

and then trying to launch the same command. I got the same result.

For the following problem solving steps I will note a few things:

Some short googling found me some useful older issues:

That last one was the most helpful.

I guessed (correctly) that this was a permission issue within the container so:

# docker run --rm --name red-1-container -p 6379:6379 -v /redis/conf/:/redis-settings/ chown -Rv redis:redis /redis-settings/ 
ownership of `/redis-settings/redis.conf' retained as redis:redis
ownership of `/redis-settings/redis2.conf' retained as redis:redis
ownership of `/redis-settings/redis1.conf' retained as redis:redis
ownership of `/redis-settings/' retained as redis:redis

The owner of the directory was correct and the files are where they are supposed to be, what's the issue then?

# docker run --rm --name red-1-container -p 6379:6379 -v /redis/conf/:/redis-settings/ redis whoami
root

well thats not right. I'm supposed to be running the server as redis:redis.

And the winning command is

# docker run --rm --name red-1-container -p 6379:6379 -v /redis/conf/:/redis-settings/ redis gosu redis:redis redis-server /redis-settings/redis1.conf

I'm not sure exactly where the problem resides, but redis does not seem to be taking the custom config file and stepping down correctly and is instead trying to do something as root when the container firmly wants that action to be executed by redis:redis.

mut3 commented 9 years ago

hm should this issue have been opened here https://github.com/docker-library/redis instead?

yosifkit commented 9 years ago

Oh, probably :neutral_face:. I think your PR to fix the docs will be sufficient. 'Twas just the missing redis-server anyway.

RicHincapie commented 3 years ago

I was having a similar issue with Linux 18.04 LTS and Redis Container 6.0-alpine3.12: root@vmi528359:~# docker start -a redis 1:C 15 Jun 2021 13:30:48.775 # Fatal error, can't open config file '/usr/local/etc/redis/redis.conf': Permission denied

were I was -v /home/redis_conf:/usr/local/etc/redis/ and placing the redis.conf file in it.

Nothing I did with chmod from the host side worked out. The only turnaround was @mut3's, by running a temporarly container to change user and group.

tianon commented 3 years ago

I would suggest trying a dedicated support forum, such as the Docker Community Forums, the Docker Community Slack, or Stack Overflow for help figuring out where your deployment has gone wrong.