API Reference
Testcontainers
Node.js library that runs Docker containers to provide disposable databases and services for tests.
Official Documentation ↗CompatibilityThis documentation covers version
v10. Check the official docs for the latest API surface.Installation
npm
npm install --save-dev testcontainersMethods
No methods match this filter.
Testcontainers starts real services in Docker for the duration of a test and cleans them up afterward.
Key Features
- Real services instead of stubs
- Automatic container lifecycle and cleanup
- Wait strategies for readiness
Usage Notes
Pin a version and check the official docs for the API surface you depend on before upgrading.
API reference evidence
Fetched from official sources on 2026-11-08T09:53:13.312Z via WebFetch https://unpkg.com/[email protected]/build/index.d.ts.
new GenericContainer→ signature from https://unpkg.com/[email protected]/build/generic-container/generic-container.d.ts; official text: “constructor(image: string);”withExposedPorts→ signature from https://unpkg.com/[email protected]/build/generic-container/generic-container.d.ts; official text: “withExposedPorts(…ports: PortWithOptionalBinding[]): this;”getMappedPort→ signature from https://unpkg.com/[email protected]/build/test-container.d.ts; official text: “getMappedPort(port: number): number;”
FAQ
- Do I need Docker installed?
- Yes. Testcontainers requires a running Docker daemon, and tests will fail fast if it is unavailable.
- How do I wait for readiness?
- Use withWaitStrategy with a log message or port wait so the container is fully started before tests connect.
- Will containers be cleaned up?
- Yes. stop() removes them, and Ryuk reaps orphans; still call stop in afterAll to release resources promptly.
Report a problem with this API docOpens a pre-filled issue on GitHub.