Running Redis TLS with Docker-compose

DPBD90
1 min readMar 1, 2021

As you know, SSL/TLS is supported by Redis starting with version 6 as an optional feature (https://redis.io/topics/encryption).

In this tutorial, i will rewrite my setup to run test TLS with Redis 6.

Full version of code here

Create test certificates

bash gen-test-certs.sh

Build custom image to use custom configuration file

Dockerfile:

FROM redis:6.2.0
COPY ./redis0.conf /usr/local/etc/redis/redis.conf
COPY ./tests/tls/redis.crt /usr/local/etc/redis/redis.crtCOPY ./tests/tls/redis.key /usr/local/etc/redis/redis.keyCOPY ./tests/tls/ca.crt /usr/local/etc/redis/ca.crtRUN chown -R redis:redis /usr/local/etc/redisUSER rootCMD [ "redis-server", "/usr/local/etc/redis/redis.conf"]CMD [ “redis-server”, “/usr/local/etc/redis/redis.conf”]

Build new image:

docker build -t redis-tls-test:6.2.0 .

Create configuration file for each redis instance (example node-0)

Create compose file:

Install redis-cli version 6 or above before run following steps:

Create clusters

cd ./tests/tls
redis-cli --cluster create 127.0.0.1:7379 127.0.0.1:7380 127.0.0.1:7381 127.0.0.1:7382 127.0.0.1:7383 127.0.0.1:7384 --cluster-replicas 1 --tls -a redisTLSTest2021@@ --cert redis.crt --key redis.key --cacert ca.crt

Check status of new cluster:

redis-cli -p 7379 -a redisTLSTest2021@@ --cert redis.crt --key redis.key --cacert ca.crt --tls cluster nodes

--

--

DPBD90

I'm an engineer. I love to work on data and open-source systems.