whatisgithub

What is dockertest?

ory/dockertest — explained in plain English

Analysis updated 2026-06-26

4,515GoAudience · developerComplexity · 2/5Setup · easy

In one sentence

A Go library that spins up real Docker containers for databases and services during automated tests, handling startup, readiness checks, and cleanup automatically.

Mindmap

mindmap
  root((dockertest))
    Supported Services
      PostgreSQL MySQL
      MongoDB Redis
      RabbitMQ Elasticsearch
      Custom images
    Core Features
      Start containers
      Wait for readiness
      Auto cleanup
      Retry loop
    Platform Support
      Linux macOS
      Windows
      CI pipelines
    Testing Workflow
      Real database tests
      No fake databases
      Schema accuracy
      Isolated runs
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Run automated tests against a real PostgreSQL, MySQL, or MongoDB database without manual setup or teardown.

USE CASE 2

Spin up Redis or RabbitMQ containers in CI pipelines to test message queues and caching logic reliably.

USE CASE 3

Replace fragile hand-written database fakes with actual service containers that match your production schema.

USE CASE 4

Test any service that runs in Docker by launching a custom image and waiting until it is ready to accept connections.

What is it built with?

GoDocker

How does it compare?

ory/dockertestgin-gonic/examplesvirtual-kubelet/virtual-kubelet
Stars4,5154,5124,511
LanguageGoGoGo
Setup difficultyeasyeasyhard
Complexity2/52/54/5
Audiencedeveloperdeveloperops devops

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 30min

Requires Docker installed and running locally or in CI. Use v3 for new projects. Set environment variables for CI network binding as noted in the README.

License not mentioned in the explanation.

So what is it?

dockertest is a Go library that makes it easy to spin up real database and service containers during automated tests. The problem it solves is a common one in software development: when your code talks to a database, testing it properly requires either a real database or a fake one. Faking a database is tedious and fragile, because any change to your schema or queries means rewriting all the fakes. Running tests against a real database is more reliable but messy to set up. Docker, a system that can launch isolated software containers in seconds, is a good solution here, and dockertest wraps that capability into a simple Go API. The library handles the boilerplate of starting a container, waiting until the service inside it is actually ready to accept connections, running your tests, and then stopping and removing the container automatically. The waiting step matters because Docker can report a container as running before the database process inside it is accepting connections, which would cause tests to fail with confusing errors. dockertest includes a retry loop that calls a check function you provide, repeating until the service responds or a timeout is reached. Out of the box, the library has built-in support for starting PostgreSQL, MySQL, MongoDB, Redis, Cassandra, RabbitMQ, Elasticsearch, and several other services. It also allows starting any custom Docker image when the built-in options do not cover what you need. The library works on Linux, macOS, and Windows. For CI pipelines like Travis CI, it includes environment variables to control how containers bind to network interfaces. The README recommends using the newer v3 version of the library for new projects, as it has a cleaner API and fewer dependencies.

Copy-paste prompts

Prompt 1
Using the ory/dockertest Go library, write a TestMain function that starts a PostgreSQL container, waits until it accepts connections, runs the test suite, and removes the container on exit.
Prompt 2
Show me how to use ory/dockertest to spin up a Redis container in a Go test, connect to it with a Redis client, and verify the container is cleaned up after tests finish.
Prompt 3
I have a Go integration test that needs a MongoDB container. Using ory/dockertest v3, write the setup code that starts the container, retries the connection until ready, and tears it down automatically.
Prompt 4
Using ory/dockertest, how do I start a custom Docker image that is not in the built-in list, wait for its HTTP health endpoint to return 200, and then run my tests against it?
Prompt 5
Write a Go test helper using ory/dockertest that works in GitHub Actions CI, starts a MySQL container, applies my schema, and exposes the DSN as an environment variable for other tests to use.

Frequently asked questions

What is dockertest?

A Go library that spins up real Docker containers for databases and services during automated tests, handling startup, readiness checks, and cleanup automatically.

What language is dockertest written in?

Mainly Go. The stack also includes Go, Docker.

What license does dockertest use?

License not mentioned in the explanation.

How hard is dockertest to set up?

Setup difficulty is rated easy, with roughly 30min to a first successful run.

Who is dockertest for?

Mainly developer.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.