A Rust library for managing Docker container clusters from Rust. Anchor simplifies the process of downloading images, building containers, and orchestrating multi-container applications.
Features
- đŗ Docker Container Management - Create, start, stop, and monitor Docker containers
- đ Real-time Metrics - Collect detailed runtime metrics including CPU, memory, and network usage
- đ AWS ECR Integration - Seamless authentication with Amazon Elastic Container Registry
- đž Flexible Mount Support - Bind mounts, named volumes, and anonymous volumes
- đ Resource Status Tracking - Track the lifecycle status of images and containers
- đ Cross-platform - Works on Linux, macOS, and Windows
- ⥠Async/Await - Built with modern async Rust for high performance
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
# Enable AWS ECR support (optional)
= { = "0.1.0", = ["aws_ecr"] }
Quick Start
use *;
use DockerCredentials;
async
Core Concepts
Resource Status
Anchor tracks the lifecycle of Docker resources through the ResourceStatus enum:
- Missing - Image needs to be downloaded
- Available - Image is downloaded but container doesn't exist
- Built - Container exists but isn't running
- Running - Container is actively running
let status = client.get_resource_status.await?;
match status
Mount Types
Anchor supports three types of mounts:
// Bind mount - mount host directory/file into container
let bind_mount = bind;
let readonly_bind = bind_ro;
// Named volume - use Docker-managed volume
let volume_mount = volume;
let readonly_volume = volume_ro;
// Anonymous volume - create temporary volume
let anon_volume = anonymous_volume;
let readonly_anon = anonymous_volume_ro;
Container Metrics
Get detailed runtime information about your containers:
let metrics = client.get_container_metrics.await?;
println!;
println!;
println!;
println!;
println!;
println!;
AWS ECR Integration
When the aws_ecr feature is enabled, you can authenticate with Amazon ECR:
use *;
async
Advanced Usage
Custom Error Handling
use *;
async
Health Monitoring
use Duration;
use sleep;
async
Platform Support
Anchor automatically detects and adapts to your platform:
- Linux - Uses
systemctlorservicecommands to start Docker daemon - macOS - Integrates with Docker Desktop
- Windows - Supports Docker Desktop on Windows
The library automatically starts the Docker daemon when needed:
if !client.is_docker_running.await
Error Types
Anchor provides comprehensive error handling:
DockerNotInstalled- Docker is not installed on the systemConnectionError- Cannot connect to Docker daemonECRCredentialsError- AWS ECR authentication failedImageError- Image-related operation failedContainerError- Container-related operation failedIoStreamError- I/O operation failed
License
This project is licensed under the MIT License - see the LICENSE file for details.
Dependencies
bollard- Docker API clienttokio- Async runtimechrono- Date and time handlingaws-sdk-ecr- AWS ECR integration (optional)base64- Base64 encoding/decoding
Minimum Supported Rust Version (MSRV)
Rust 1.70 or higher is required.