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
go
go get github.com/testcontainers/testcontainers-goMethods
No methods match this filter.
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:
testcontainers.ErrReuseEmptyName(var error (errors.New)) — official text: “var ( reuseContainerMx sync.Mutex ErrReuseEmptyName = errors.New(“with reuse option a container name mustn’t be empty”) )” (source: https://raw.githubusercontent.com/testcontainers/testcontainers-go/v0.44.0/generic.go, fetched 2026-11-08T16:02:45+08:00)testcontainers.ErrDuplicateMountTarget(var error (errors.New)) — official text: “ ErrDuplicateMountTarget = errors.New(“duplicate mount target detected”)” (source: https://raw.githubusercontent.com/testcontainers/testcontainers-go/v0.44.0/mounts.go, fetched 2026-11-08T16:02:45+08:00)testcontainers.ErrInvalidBindMount(var error (errors.New)) — official text: “ ErrInvalidBindMount = errors.New(“invalid bind mount”)” (source: https://raw.githubusercontent.com/testcontainers/testcontainers-go/v0.44.0/mounts.go, fetched 2026-11-08T16:02:45+08:00)
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).
testcontainers.GenericContainer→ signature from https://raw.githubusercontent.com/testcontainers/testcontainers-go/v0.44.0/generic.go; official text: “func GenericContainer(ctx context.Context, req GenericContainerRequest) (Container, error) {”Container.MappedPort→ signature from https://raw.githubusercontent.com/testcontainers/testcontainers-go/v0.44.0/docker.go; official text: “func (c *DockerContainer) MappedPort(ctx context.Context, port string) (network.Port, error) {”Container.Terminate→ signature from https://raw.githubusercontent.com/testcontainers/testcontainers-go/v0.44.0/docker.go; official text: “func (c *DockerContainer) Terminate(ctx context.Context, opts …TerminateOption) error {”
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.
Report a problem with this API docOpens a pre-filled issue on GitHub.