testcontainers-go

Programmatically spin up disposable Docker containers for Go integration and smoke tests, then tear them down automatically.

Library
Go
vv0.44.0
4,964stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
91/100Excellent
Development Activity96
Maintenance96
Community72
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
83/100Excellent
Architecture85
Code Quality88
Innovation78
Learning Curve80

Testcontainers for Go is a Go package that makes it simple to create and clean up container-based dependencies for automated integration and smoke tests. Instead of mocking a database, message broker, or third-party service, tests spin up the real thing in a Docker container, run against it, and let the library handle teardown when the test session ends.

The library ships a core testcontainers package for defining arbitrary ContainerRequests plus a large catalog of purpose-built modules — Postgres, MySQL, Kafka, Redis, LocalStack, and dozens more — that wrap the raw container API with typed, service-specific constructors and connection-string helpers. A wait package provides composable readiness strategies (HTTP, log line, SQL ping, exec, health check) so tests only proceed once a container is actually ready to serve traffic.

What You Get

  • A core testcontainers API (GenericContainer, ContainerRequest, Container interface) for running any Docker image as a test dependency, with full control over ports, env vars, mounts, and networks.
  • Over 80 ready-made modules under modules/ (Postgres, MySQL, MongoDB, Kafka, Redis, Elasticsearch, LocalStack, RabbitMQ, and more) that expose typed constructors and connection-string helpers instead of raw container config.
  • A composable wait package with strategies for HTTP readiness, log-line matching, SQL connectivity, exec-based checks, TLS, and health-check polling, combinable via wait.ForAll.
  • Automatic resource cleanup via a Ryuk-based reaper process and testcontainers.CleanupContainer/terminate helpers, so containers don’t leak between test runs even on failure or interruption.
  • Podman and Docker Desktop compatibility with auto-detection of the container runtime via ProviderType, plus support for building images from a Dockerfile on the fly for testing custom builds.
  • A network package for creating isolated Docker networks so multi-container test scenarios (e.g. an app container talking to a database container) can communicate without touching the host network.

Common Use Cases

  • Running integration tests against a real Postgres or MySQL instance instead of an in-memory or mocked database, catching driver- and dialect-specific bugs that mocks miss.
  • Testing message-queue-driven code end-to-end by spinning up Kafka, RabbitMQ, or Redis Streams in CI without a shared, stateful test environment.
  • Verifying Docker Compose-based application stacks in CI by launching multiple interconnected containers on a shared test network and asserting on their combined behavior.
  • Smoke-testing a custom Docker image by building it directly from a Dockerfile inside the test and asserting the container starts, becomes healthy, and serves expected responses.
  • Testing cloud-service integrations locally and in CI using LocalStack or provider-emulator modules instead of hitting real AWS/GCP/Azure accounts from the test suite.

Under The Hood

Architecture The library is organized around a small core (testcontainers.go, container.go, provider.go, generic.go) that defines the Container and GenericProvider interfaces, with a DockerProvider implementation in docker.go that talks to the Docker/Podman engine via the moby/moby/client SDK. Everything else — the wait package for readiness strategies, the network package for Docker network management, the exec package for in-container command execution, and 80+ modules under modules/ — is built as composable, independent packages layered on top of that core Container/ContainerRequest abstraction, so a change to the core request/response types is the one place that would ripple across the entire module catalog. Internal concerns like Docker host resolution and session bookkeeping live under internal/core and internal/config, kept separate from the public API surface.

Tech Stack Written in Go (module targets Go 1.25, toolchain 1.25.9) with github.com/moby/moby/client and github.com/moby/moby/api as the low-level Docker engine client, github.com/cpuguy83/dockercfg for registry auth, github.com/moby/go-archive and github.com/moby/patternmatcher for build-context handling, github.com/google/uuid for session IDs, github.com/shirou/gopsutil/v4 for host introspection, and github.com/stretchr/testify as the test-assertion library used throughout its own test suite. Each of the 80+ modules under modules/ (Postgres, Kafka, Redis, LocalStack, etc.) is a self-contained Go package with its own go.mod, pulling in the relevant client driver for that service only when that module is used.

Code Quality The root package alone carries around 29 _test.go files, and nearly every module and the wait package ship parallel _test.go coverage, all built on testify for assertions. The project enforces golangci-lint with errorlint, govet, gocritic, nakedret, nolintlint, and perfsprint enabled, plus gofumpt/gci formatting with import-section ordering, run via dedicated ci-lint-go.yml and ci-test-go.yml GitHub Actions workflows alongside CodeQL and OSSF Scorecard scans. Errors are returned as typed Go error values throughout rather than panicking, with errors.Is/errors.As-style wrapping expected by the errorlint lint rule.

What Makes It Unique Rather than a single generic “run a container” helper, the project maintains an extensive, community-curated catalog of per-service modules that encode the correct readiness strategy, default ports, and connection-string format for each supported service, removing a large class of flaky-test bugs that come from hand-rolled wait logic. Its Ryuk-based reaper guarantees container cleanup even when a test process crashes or is killed mid-run, which ad hoc docker run-based test setups typically don’t handle.

Used by 21 apps in this directory

Go
85%
Apache 2.0

Argo Workflows

Devops · Data Engineering

16,943

The most popular Kubernetes-native workflow engine for orchestrating containerized DAGs, ML pipelines, CI/CD, and parallel batch jobs at scale.

View details
95
Repo Health
90
Technical
68
Dependency
Built with
Go85%
TypeScript11%
Updated yesterday
Go
52%
MIT

Bytebase

Devops

14,449

An open-source database CI/CD and DevSecOps platform — schema migration review, GitOps-driven changes, data masking, and access control across MySQL, PostgreSQL, Oracle, Snowflake, MongoDB, and more.

View details
91
Repo Health
73
Technical
69
Dependency
Built with
Go52%
TypeScript39%
Updated yesterday
Go
59%
Apache 2.0

Cog

AI Development · Devops · Developer Tools

9,464

An open-source CLI that packages machine learning models into standard, production-ready Docker containers — no Dockerfile wrangling, no CUDA version hell.

View details
90
Repo Health
88
Technical
69
Dependency
Built with
Go59%
Rust17%
HTML13%
Updated 4 days ago
Go
73%
Other

Convoy

Developer Tools · Devops

2,862

Convoy is an open-source, cloud-native webhooks gateway that ingests events over HTTP or straight from Kafka, SQS, Google Pub/Sub, and RabbitMQ, then reliably delivers them to subscriber endpoints with signed payloads, automatic retries, circuit breaking, and JavaScript-based transformations.

View details
89
Repo Health
81
Technical
66
Dependency
Built with
Go73%
TypeScript13%
HTML12%
Updated yesterday
Go
92%
AGPL 3.0

Cozy Stack

File Storage · Productivity

1,270

Self-hosted personal cloud platform that unifies your files, apps, and devices in one private space you fully control.

View details
94
Repo Health
77
Technical
67
Dependency
Built with
Go92%
Updated 2 days ago
Go
73%
Other

Flipt

Devops · Developer Tools

4,884

Git-native feature flag platform that stores, versions, and deploys feature toggles directly in your own Git repositories with no external database required.

View details
89
Repo Health
83
Technical
70
Dependency
Built with
Go73%
TypeScript26%
Updated yesterday
TypeScript
49%
AGPL 3.0

Grafana

Monitoring · Analytics

76,498

The open-source observability platform that unifies metrics, logs, and traces from any data source into dynamic, queryable dashboards.

View details
95
Repo Health
91
Technical
65
Dependency
Built with
TypeScript49%
Go45%
Updated today
Go
84%
MIT

Hatchet

AI Development · Developer Tools · Automation

7,812

A Postgres-backed orchestration engine for background tasks, AI agents, and durable workflows that replaces Redis queues and multi-datastore durable execution platforms with a single self-hostable service.

View details
88
Repo Health
83
Technical
68
Dependency
Built with
Go84%
PLpgSQL11%
Updated today
Go
58%
MIT

hoop

Security · Monitoring

805

A wire-protocol gateway that enforces data masking, command blocking, approval workflows, and full session recording for engineers and AI agents accessing production infrastructure.

View details
85
Repo Health
80
Technical
65
Dependency
Built with
Go58%
Clojure19%
JavaScript14%
Updated 2 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search