For production purposes, we recommend using publicly trusted certificates issued by a Certificate Authority (CA).
Components
- Redis image built by Minimus: Redis container configured to require secure connections via TLS.
- Dynamic certificate generation via OpenSSL:
- certgen.sh script: Shell script that generates a custom CA, server, and client certificates using OpenSSL.
- minidebug image: A Minimus dev toolkit that provides a shell, OpenSSL, and other utilities used to generate the certificates.
What this guide demonstrates
- TLS handshake validation
- Server/client certificate trust
- Basic auth and Redis operations
- Image compatibility
Directory structure
Deploy Redis with TLS certificates
Step 1: Generate TLS certificates
1
Save script that generates TLS certificates
Save the following script to a file named
certgen.sh. The script is used to generate the TLS certificates and store them in a certs folder on the host.certgen.sh
2
Save Docker Compose configuration
Save the following YAML file to run with Docker Compose. It uses the Minimus minidebug image to generate the certificates with the
certgen.sh shell script. Minidebug is a Minimus dev toolkit that provides a shell, OpenSSL, and other utilities. The certificates will be persisted in the certs volume on the host.create-certs.yml
3
Generate certificates
Run the following to generate the certificates:
- Self-signed CA certificate (
ca.pem) - Server certificates (
server-cert.pem,server-key.pem) with SANs:Redis,localhost, and192.168.20.3 - Client certificates for
testuser(client.csr,client-key.pem)
Step 2: Deploy Redis server
1
Save Docker Compose script
Save the following Docker Compose script to a file named
docker-compose.yml. This script sets up the Redis service with a healthcheck, mounts a volume with the certificates, and maps port 6379. The container is configured with "--tls-auth-clients", "yes" to require client certificates.docker-compose.yml
2
Run Redis
Start the Redis container:
Step 3: Test your Redis server
We will use redis-cli to connect over TLS and run tests. For example, here are a few commands you can try out:-
Check server info and health:
-
Add test key to a database:
Verify the key:Redis has numbered logical databases (default 0–15) rather than named databases.
-
Test data persistence:
Stop the container, then restart it:Save dataCheck the key you added in the previous step:Get key
-
Delete the key: