docker builds redis cluster

Posted by legacyblade on Mon, 13 Jul 2020 16:48:41 +0200

docker builds redis cluster

1. Download the redis image

docker pull redis

2. Prepare the configuration fileRedis.conf

mkdir /home/docker/redis/  
wget https://raw.githubusercontent.com/antirez/redis/3.0/redis.conf -O /home/docker/redis/redis.conf
cd /home/docker/redis/  
sed -i 's/# slaveof <masterip> <masterport>/slaveof redis-master 6379/g' redis.conf  

3. Start the redis container

docker run --name redis-master -p 6379:6379 -d redis
docker run --link redis-master:redis-master -v /home/docker/redis/redis.conf:/usr/local/etc/redis/redis.conf --name redis-slave1 -d redis redis-server /usr/local/etc/redis/redis.conf
docker run --link redis-master:redis-master -v /home/docker/redis/redis.conf:/usr/local/etc/redis/redis.conf --name redis-slave2 -d redis redis-server /usr/local/etc/redis/redis.conf
docker run --link redis-master:redis-master -v /home/docker/redis/redis.conf:/usr/local/etc/redis/redis.conf --name redis-slave3 -d redis redis-server /usr/local/etc/redis/redis.conf 

4. See if the redis cluster succeeded with a command

docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
e1b229de3a36        redis               "docker-entrypoint.sh"   About an hour ago   Up 31 minutes       6379/tcp                 redis-slave3
169d7295d138        redis               "docker-entrypoint.sh"   About an hour ago   Up 31 minutes       6379/tcp                 redis-slave2
ebb4e5414b9f        redis               "docker-entrypoint.sh"   About an hour ago   Up 31 minutes       6379/tcp                 redis-slave1
763c9cca29d4        redis               "docker-entrypoint.sh"   About an hour ago   Up 31 minutes       0.0.0.0:6379->6379/tcp   redis-master

If the above information appears, the building has been successfully completed.
PS: You can view the log through [docker logs-f container id or container name],
I encountered can't open config file /usr/local/etc/redis/Redis.confError
The first feeling isRedis.confWithout read and write permissions, 777 still reported this error, which is depressing.
It was not until selinux was turned off.

Reference: https://segmentfault.com/a/1190000004353368 Thank your forefathers for their accumulation.

Topics: Redis Docker SELinux