Testcontainers for Rust

Integration-test against throwaway Docker containers from within Rust

Library
Cargo
v0.28.0
1,134 stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
69 /100 Good
Development Activity 60
Maintenance 48
Community 68
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
83 /100 Excellent
Architecture 84
Code Quality 85
Innovation 80
Learning Curve 82

Testcontainers for Rust is the official Rust fork of the Testcontainers project. It provides a lightweight API for spinning up disposable Docker containers — databases, message brokers, or any Dockerized dependency — directly from your Rust integration tests, and tears them down automatically when the test finishes.

You describe the image you need, wait conditions, exposed ports, and environment, then start it with either an async (Tokio) or blocking runner. A collection of ready-to-use image modules and a generic image builder mean you can test against real services instead of mocks, with reproducible setup on every run.

What You Get

  • A generic image builder plus ready-to-use image modules for common services
  • Async (Tokio) and blocking runner APIs behind a shared container interface
  • Configurable wait strategies (log messages, health checks, ports) before a container is considered ready
  • Automatic container cleanup via a watchdog so no resources leak after tests finish
  • Fine-grained control over exposed ports, environment variables, networks, and mounts

Common Use Cases

  • Running integration tests against a real database (Postgres, Redis, MySQL) instead of mocks
  • Testing code that talks to message brokers, object stores, or other Dockerized services
  • Providing reproducible, isolated dependencies in CI without shared external infrastructure
  • Spinning up docker-compose stacks for multi-service integration scenarios

Under The Hood

Architecture — The crate (in testcontainers/src/) centers on a core::Image trait describing how to build and wait on a container, runners/ implementing async (AsyncRunner) and blocking (SyncRunner) execution over a shared container abstraction, and a watchdog.rs background task that reaps containers even on panic. Docker interaction goes through the bollard client; compose/ adds docker-compose orchestration, images/ provides a GenericImage and module definitions, and buildables/ supports building images on the fly.

Tech Stack — Rust (edition 2021, rust-version 1.88), built on Tokio with bollard for the Docker API, reqwest/http for HTTP wait strategies, russh for SSH-based flows, serde/serde_json/serde_with for config, and thiserror for errors. Optional features gate compose support, blocking runners, and credential handling; distributed as a Cargo workspace with the single testcontainers member.

Code Quality — The code is idiomatic async Rust with clear module separation, typed errors via thiserror, and builder-style ergonomics. The project maintains a documented DESIGN_PRINCIPLES.md, CI workflows, and test images under testimages/, reflecting a mature, well-tested codebase with 30M+ total downloads.

API Design — The fluent ImageExt builder (.with_exposed_port, .with_wait_for, .with_env_var, .start()) makes container setup read almost declaratively, and the parallel async/blocking runner APIs let users pick the model matching their tests with minimal boilerplate — a container is often ready in a handful of chained calls.

Used by 5 apps in this directory

Rust
99%
Other

Fluree DB

Databases

469

A temporal, verifiable graph database with git-like branching, integrated vector/text/geo search, and RDF/SPARQL/JSON-LD/openCypher support — benchmarked at 10.4x faster than the next database on the full Wikidata dump.

View details
87
Repo Health
74
Technical
65
Dependency
Built with
Rust 99%
Updated 6 days ago
Rust
73%
Other

iii

Developer Tools · Devops

18,814

Compose, extend, and observe every backend service in real time using three primitives: Workers, Functions, and Triggers.

View details
87
Repo Health
85
Technical
65
Dependency
Built with
Rust 73%
TypeScript 16%
Updated 6 days ago
Rust
68%
MIT

Readur

Bookmarks Archiving · File Storage · Knowledge Management

797

A self-hosted document management system that OCRs, indexes, and makes every PDF, scan, and Office file instantly searchable.

View details
81
Repo Health
78
Technical
67
Dependency
Built with
Rust 68%
TypeScript 30%
Updated 5 days ago
Rust
98%

Stalwart

Collaboration

14,848

All-in-one secure mail and collaboration server covering IMAP, JMAP, SMTP, CalDAV, CardDAV, and WebDAV in a single memory-safe Rust binary.

View details
89
Repo Health
81
Technical
65
Dependency
Built with
Rust 98%
Updated 6 days ago
Rust
97%
Apache 2.0

Volga

Data Engineering

161

A Rust-based real-time data processing engine for AI/ML feature computation, built on Apache DataFusion and Arrow — positioned as an alternative to Flink, Spark, Chronon, and OpenMLDB with unified streaming, batch, and request-time execution.

View details
67
Repo Health
67
Technical
72
Dependency
Built with
Rust 97%
Updated 6 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