docker-wrapper
A comprehensive, type-safe Docker CLI wrapper for Rust applications.
Features
- Comprehensive Docker CLI coverage (80+ commands implemented)
- Type-safe builder pattern API
- Async/await support with Tokio
- Real-time output streaming
- Docker Compose support (optional)
- Pre-configured container templates (Redis, PostgreSQL, MySQL, MongoDB, Nginx)
- Docker context management for remote Docker hosts
- Docker builder commands for build cache management
- Network and volume management
- Zero unsafe code
- Extensive test coverage (750+ tests)
Installation
Add to your Cargo.toml
:
[]
= "0.5"
= { = "1", = ["full"] }
Minimum Supported Rust Version (MSRV): 1.89.0
Enable Docker Compose support:
[]
= { = "0.5", = ["compose"] }
Quick Start
use ;
async
Important: The
DockerCommand
trait must be imported to use the.execute()
method on any Docker command. This trait provides the core execution functionality for all commands.
Docker Builder Example
use ;
async
Container Templates
Templates provide pre-configured containers with sensible defaults and best practices:
[]
= { = "0.8", = ["templates"] }
Quick example:
use ;
async
📖 Complete Template Documentation - Comprehensive guide with examples for all templates
Docker Context Management
use ;
async
Available templates:
- Redis:
RedisTemplate
,RedisSentinelTemplate
,RedisClusterTemplate
,RedisEnterpriseTemplate
,RedisInsightTemplate
- Databases:
PostgresTemplate
,MysqlTemplate
,MongodbTemplate
- Web Servers:
NginxTemplate
All templates support custom images, platforms, persistence, and resource limits. See the Template Documentation for complete usage examples.
When to Use docker-wrapper
docker-wrapper is ideal for:
- CLI tools and automation scripts - Familiar Docker CLI behavior
- Docker Compose workflows - Native compose command support
- Development tools - Container management for dev environments
- Shell script migration - Type-safe Rust alternative to bash scripts
- Cross-platform support - Works with Docker, Podman, Colima, etc.
Choosing between Docker Rust libraries? See our comprehensive Comparison Guide comparing docker-wrapper vs bollard vs testcontainers-rs.
Documentation
For comprehensive documentation, examples, and API reference:
- API Documentation - Complete API reference with examples
- Template Guide - Comprehensive template documentation with examples
- Examples - Working examples for common use cases
- Testing Guide - Best practices for testing with docker-wrapper
- Comparison Guide - docker-wrapper vs other Docker Rust libraries
- Command Coverage - Docker CLI command implementation status
- GitHub Repository - Source code and issue tracking
Examples
The examples/
directory contains practical examples:
basic_usage.rs
- Common Docker operationsbasic_docker_patterns.rs
- Essential Docker patterns and best practicesexec_examples.rs
- Container command executionlifecycle_commands.rs
- Container lifecycle managementrun_examples.rs
- Advanced run command usagestreaming.rs
- Real-time output streamingdocker_compose.rs
- Docker Compose usage (requirescompose
feature)debugging_features.rs
- Debugging and inspection featuressystem_cleanup.rs
- System maintenance and cleanupcomplete_run_coverage.rs
- Comprehensive run command optionstemplate_usage.rs
- Container templates usage (requirestemplates
feature)network_volume_management.rs
- Network and volume managementredis_cluster.rs
- Redis cluster setup exampletest_sentinel.rs
- Redis Sentinel high availability exampleredis_enterprise_template.rs
- Redis Enterprise cluster with automatic initializationtesting_basics.rs
- Basic testing patterns with docker-wrappertest_fixtures.rs
- Reusable test fixtures for common services
Run examples:
Contributing
Contributions are welcome! Please see our Contributing Guide for details.
License
Licensed under the MIT license (LICENSE or http://opensource.org/licenses/MIT).