Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Redis on docker with a different configuration file?

I would like to set a password on my Redis server running on docker. I have followed the instcruction on https://registry.hub.docker.com/_/redis/:

1.I have created a folder with a Dockerfile containing:

FROM redis  
COPY redis.conf /usr/local/etc/redis/redis.conf  
CMD [ "redis-server", "/usr/local/etc/redis/redis.conf" ] 

2.I have added a redis.conf file with:

requirepass thepassword

3.I built the image using:

docker build -t ouruser/redis .

4.I started the container:

docker run --name my-redis -p 0.0.0.0:6379:6379 -d ouruser/redis redis-server --appendonly yes

The redis server does not have any password ! I do not understand why.

like image 462
poiuytrez Avatar asked Jul 28 '15 09:07

poiuytrez


1 Answers

The run command:

docker run --name my-redis -p 0.0.0.0:6379:6379 -d ouruser/redis redis-server --appendonly yes

Overrides the CMD defined in the Dockerfile with redis-server --appendonly yes, so your conf file will be being ignored. Just add the path to the conf file into your run command:

docker run --name my-redis -p 0.0.0.0:6379:6379 -d ouruser/redis redis-server /usr/local/etc/redis/redis.conf --appendonly yes

Alternatively, set up an entrypoint script or add --appendonly yes to the CMD instruction.

like image 72
Adrian Mouat Avatar answered Sep 28 '22 02:09

Adrian Mouat