Skip to content

testing with docker

Ryan Culpepper edited this page Jun 2, 2024 · 10 revisions

Testing with Docker

This page describes how to create testing environments (ie, database servers) using Docker.


PostgreSQL

References:

docker pull postgresql

with MD5 authentication and TLS

docker run --name testdb-postgres --publish 5432:5432 \
  -e POSTGRES_USER=rkt \
  -e POSTGRES_PASSWORD=rktpwd \
  -e POSTGRES_INITDB_ARGS=--auth-host=scram-sha-256 \
  -e POSTGRES_HOST_AUTH_METHOD=scram-sha-256 \
  postgres \
  -c 'ssl=on' \
  -c 'ssl_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem' \
  -c 'ssl_key_file=/etc/ssl/private/ssl-cert-snakeoil.key'
# ... run tests ...
docker rm --force testdb-postgres

with SCRAM-SHA-256 authentication and TLS

docker run --name testdb-postgres --publish 5432:5432 \
  -e POSTGRES_USER=rkt \
  -e POSTGRES_PASSWORD=rktpwd \
  -e POSTGRES_INITDB_ARGS=--auth-host=scram-sha-256 \
  -e POSTGRES_HOST_AUTH_METHOD=scram-sha-256 \
  postgres \
  -c 'ssl=on' \
  -c 'ssl_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem' \
  -c 'ssl_key_file=/etc/ssl/private/ssl-cert-snakeoil.key'
# ... run tests ...
docker rm --force testdb-postgres

The server can be shut down with Ctrl-C, but the container must still be removed.


MySQL

References:

docker pull mysql
docker run --name testdb-mysql --publish 3306:3306 \
  -e MYSQL_ROOT_PASSWORD=myrootpwd \
  -e MYSQL_USER=rkt \
  -e MYSQL_PASSWORD=rktpwd \
  -e MYSQL_DATABASE=rkt \
  -d mysql
# ... run tests ...
docker rm --force testdb-mysql

Note: latest version (8) defaults to caching-sha2-password, so client must connect with ssl=yes first.

MariaDB

docker pull mariadb

The server can be started using the same command as for mysql, just replacing mysql with mariadb.


Oracle

References:

Fetching docker images:

  • podman login container-registry.oracle.com --- requires account
  • podman pull container-registry.oracle.com/database/free:latest
  • As of 6/2/2024, this fetches "Oracle Database Free Release 23ai (23.4.0.0)", which has the SID "FREE". The test-dsn.rktd entries have been updated.

Installing Oracle ODBC libs on host:

docker run --name testdb-oracle --publish 1521:1521 --publish 5500:5500 \
  -e ORACLE_SID=FREE \
  -e ORACLE_PWD=orapwd \
  --shm-size=1g \
  -d container-registry.oracle.com/database/free
# ... run tests ...
docker rm --force testdb-oracle

DB2

References:

docker pull ibmcom/db2

Setting up ODBC:

docker run --name testdb-db2 -p 50000:50000 \
  --privileged=true -e LICENSE=accept \
  -e DB2INST1_PASSWORD=db2pwd \
  -e DBNAME=testdb \
  ibmcom/db2
# ... run tests ...
docker rm --force testdb-db2

MS SQL Server

References:

docker run --name testdb-ms --publish 1433:1433 \
  -e 'ACCEPT_EULA=Y' \
  -e 'SA_PASSWORD=abcdEFGH89!' \
  -e 'MSSQL_PID=Express' \
  mcr.microsoft.com/mssql/server
# ... run tests ...
docker rm --force testdb-ms

Cassandra

References:

docker run --name testdb-cassandra --publish 9042:9042 \
  cassandra
# ... run tests ...
docker rm --force testdb-cassandra