Crates.io | compose-rs |
lib.rs | compose-rs |
version | 0.0.3 |
source | src |
created_at | 2024-04-18 20:57:11.282376 |
updated_at | 2024-04-18 22:14:06.743616 |
description | A Rust library to execute docker-compose commands and monitor compose stacks |
homepage | |
repository | https://github.com/tomvoet/compose-rs |
max_upload_size | |
id | 1212903 |
size | 33,959 |
compose-rs is a Rust library designed to manage Docker Compose environments programmatically. It provides a straightforward API for executing common Docker Compose commands directly from Rust code.
up
, down
, ps
, and stats
.Add to your Cargo.toml
:
[dependencies]
+ compose-rs = "0.0.3"
This example demonstrates how to bring up a Docker Compose environment and monitor the stats of running services in real-time.
use compose_rs::{Compose, ComposeCommand};
fn main() {
let compose = Compose::builder()
.path("docker-compose.yml")
.build()
.unwrap();
// Execute the `up` command to start services defined in the Docker Compose file
if let Err(e) = compose.up().exec() {
eprintln!("Error starting services: {}", e);
}
// Stream stats and print them in real-time for each service
compose
.stats()
.stream()
.unwrap()
.into_iter()
.for_each(|service| {
println!("{:?}", service);
});
// After monitoring, bring down the services
if let Err(e) = compose.down().exec() {
println!("Error stopping services: {}", e);
}
}
For detailed API documentation and advanced usage, please refer to the generated documentation.
Contributions are welcome! Please feel free to contribute by opening issues or submitting pull requests.
compose-rs is licensed under the MIT license. See LICENSE for details.