1
votes

I want to set up master-slave redis in docker container; And I want to use redis.conf in slave's container;

Test environment :win7+Docker Quickstart Terminal;

Before start,Create three file redis-6379、redis-6380、redis-6381 to this path: '~/Desktop/redis/';Then create redis.conf foreach file;(Using the official configuration);Then use Docker Quickstart run command :

cp -rf ~/Desktop/redis/ /usr/local/

files content

I do this in the fllowing steps:

1、modify redis.conf (redis-6381/redis-6380)

slaveof 172.17.0.2 6379

2、specify this redis.conf

docker run -v /usr/local/redis/redis-6381/redis.conf:/usr/local/etc/redis/redis.conf --name redis-6381 -p 6381:6379 -d redis redis-server  /usr/local/etc/redis/redis.conf

docker logs gives me: Configuration loaded;Actually redis.conf has no effect; info replication show,this redis still be a master role;

Then,I tried in this way,it works:

docker run --name redis-6381 -p 6381:6379 -d redis redis-server slaveof 172.17.0.2 6379

So,why redis.conf cann't work ?

1
Get inside the container and see if /usr/local/etc/redis/redis.conf has the slaveof value or not?Tarun Lalwani
'/usr/local/etc/redis/redis.conf' is empty;baoyun
That means /usr/local/redis/redis-6381/redis.conf on your host machine doesn't existsTarun Lalwani
that's the problem;I use command 'vim /usr/local/redis/redis-6381/redis.conf` on my host machine;this file exitsts, content correct;baoyun
What are you using? Docker for mac ? Add your infrastructure detailsTarun Lalwani

1 Answers

3
votes

You need to use -v ~/Desktop/redis/redis-6381/redis.conf:/usr/local/etc/redis/r‌​edis.conf instead from /usr/local`

The problem is that when you work on Windows, Docker will automatically share some of your Drives to the VM in which docker runs. So your paths will work.

But MingW may be hosting the /usr/local folder somewhere else and showing it to you mounted at /usr/. I don't use windows, so can't confirm that for you.

When you use -v /usr/local/redis/redis-6381/redis.conf:/usr/local/etc/redis/redis.conf the host path doesn't translate insider docker and hence a blank file is created and mapped.