Components
- Redis image: Redis container configured with to require secure connections via TLS.
- certgen.sh script: 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
1
Save certgen.sh
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 create-certs.yml
Save the following YAML file to run with Docker Compose. It uses the Minimus minidebug image to generate the certificates with the
certgen.shshell 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:
TLS certificates
The scriptcertgen.sh generates the following self-signed 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)
4
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
5
Run Redis
Start the Redis container:
6
Run tests over redis-cli
We will use redis-cli to connect over TLS and run tests. For example, here are a few commands you can try out:
-
Check sever 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: