Skip to content

testing with docker

Ryan Culpepper edited this page Jun 24, 2020 · 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

sudo docker run --rm --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 --rm --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 \
  -d 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 command above


MySQL

References:

docker pull mysql
docker run --rm --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.

Clone this wiki locally