Components
- MariaDB image: MariaDB container configured with the secure configuration for client authentication.
- 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 MariaDB operations
- Image compatibility
Directory Structure
Deploy MariaDB 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) - Client certificates for
testuser(client-cert.pem,client-key.pem,client.csr)
644 and owned by UID 1000 . Certificate permissions are adjusted to support non-root containers. The certificates will be mounted into the MariaDB container.4
Save Docker Compose script
Save the following Docker Compose script to a file named
docker-compose.yml. This script sets up the MariaDB service with a healthcheck, mounts a volume with the certificates, and maps port 3307 on the host to port 3306 on the container.docker-compose.yml
5
Run MariaDB
Start the MariaDB container in detached mode:
6
Run tests over mysql or mariadb-client
Make sure you are in the right folder, where the certs are available:Use mysql or mariadb-client to connect over TLS and run tests. For example, here are a few commands you can try out:
-
Connect to the db:
-
Create and list databases:
-
Show server version:
-
Check that TLS is active: