I wanted to have below configuration:
So for Master, I have created dockerfile like below:
FROM redis
COPY redis.conf /etc/redis/redis.conf
COPY sentinel.conf /etc/redis/sentinel.conf
CMD [ "redis-server", "/etc/redis/redis.conf" ]
CMD [ "redis-sentinel", "/etc/redis/sentinel.conf" ]
CMD [ "redis-sentinel", "/etc/redis/sentinel.conf" ]
All looks good and when I try to run docker container it doesn't throw any error and looks fine. But when I try to connect to container using redis-cli, I am getting below error.
error: Could not connect to Redis at 127.0.0.1:6379: Connection refused
I am not able to understand why it is not able to connect? Also if anyone can tell me if I am creating the dockerfile correct way?
Note : Trying below command to connect
docker exec -it rdbcontainer redis-cli
Dockerfile can only have one CMD instruction, and if you specified multiple, the last one will be execute. So this is the reason you can access sentinel but not redis server.
If you want to execute multiple command, you should use RUN instead and use CMD for the main process.
But I don't recommend to use RUN for sentinel or redis-server as Docker container is very lightweight and each container should focus on its own process(CMD). For sentinels and redis-server, you can create multiple containers on same host(docker-compose should be a potential solution).