-
-
Notifications
You must be signed in to change notification settings - Fork 17
testing with docker
Ryan Culpepper edited this page Jun 2, 2024
·
10 revisions
This page describes how to create testing environments (ie, database servers) using Docker.
References:
- https://hub.docker.com/_/postgres
- for scram-sha-256 authentication: https://github.com/docker-library/postgres/issues/726, https://github.com/docker-library/postgres/pull/713#issuecomment-614854429
- for TLS: https://github.com/docker-library/postgres/pull/152; that doesn't work, but easy to use snakeoil instead
docker pull postgresql
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
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.
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.
docker pull mariadb
The server can be started using the same command as for mysql
, just replacing mysql
with mariadb
.
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
References:
- https://hub.docker.com/r/ibmcom/db2
- https://www.ibm.com/support/pages/tech-tip-setting-unixodbc-driver-manager-and-odbc-environment-db2
- https://www.ibm.com/support/pages/howto-setup-odbc-application-connectivity-linux
docker pull ibmcom/db2
Setting up ODBC:
- https://www.ibm.com/support/knowledgecenter/SSEPGG_11.1.0/com.ibm.db2.luw.apdv.cli.doc/doc/t0061216.html
- https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.swg.im.dbclient.install.doc/doc/t0060690.html
- can avoid db2dsdriver.cfg by using connection string, eg
DRIVER=Db2;Database=testdb;Hostname=localhost;Port=50001;UID=db2inst1;PWD=db2pwd
- connecting to server is very slow if there is no existing connection
- adding
'keep-unused-connection
to test suite drops time from 150s to less than 1s - probably related: https://stackoverflow.com/questions/25788253/connecting-to-db2-through-odbc-is-extremely-slow (see answer re
ACTIVATE
)
- adding
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
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
References:
docker run --name testdb-cassandra --publish 9042:9042 \
cassandra
# ... run tests ...
docker rm --force testdb-cassandra