API Reference

Testcontainers Go

A Go library that runs Docker containers to provide disposable dependencies for integration tests.

Official Documentation ↗
CompatibilityThis documentation covers version v0.30. Check the official docs for the latest API surface.

Installation

gogo get github.com/testcontainers/testcontainers-go

Methods

Testcontainers Go starts services in Docker, exposes mapped ports, and cleans them up.

Key Features

  • Generic and module-specific containers
  • Mapped ports and wait strategies
  • Automatic cleanup via Ryuk

Usage Notes

Pin a version and check the official docs for the API surface you depend on before upgrading.

Errors

The official API reference declares the following error types:

API reference evidence

Fetched from official sources on 2026-11-08T16:02:45+08:00 via WebFetch pkg.go.dev + PowerShell Invoke-WebRequest raw.githubusercontent.com (testcontainers/testcontainers-go v0.44.0) + 模块 zip (proxy.golang.org v0.44.0).

FAQ

Is a Docker daemon required?
Yes. The tests need a running Docker daemon; CI images must provide one or use a remote Docker host.
How do I wait until the service is ready?
Use a wait strategy such as waiting for a log line or a port, so tests do not connect before the service is up.
How do I use module-specific helpers?
Import packages like testcontainers-go/modules/postgres which wrap common images with connection string helpers.