3个版本
0.1.3 | 2022年2月10日 |
---|---|
0.1.2 | 2021年8月31日 |
0.1.1 | 2021年8月29日 |
0.1.0 |
|
#727 in Unix APIs
在 coyote 中使用
15KB
235 行
EggShell (for rust): 自动销毁你创建的容器
EggShell在结构体被丢弃时自动清理它创建的所有容器。它使用bollard docker工具包,以及tokio来管理容器。
要使用,只需通过它创建容器并等待EggShell消失。它将自动触发其Drop
实现,这将销毁容器。
展示计数的示例(来自examples/basic.rs
源代码)
use std::sync::Arc;
#[tokio::main]
async fn main() -> Result<(), eggshell::Error> {
let docker = Arc::new(tokio::sync::Mutex::new(
bollard::Docker::connect_with_unix_defaults().unwrap(),
));
let mut gs = eggshell::EggShell::new(docker.clone()).await?;
let count = docker
.lock()
.await
.list_containers::<String>(None)
.await
.unwrap()
.len();
println!(
"before: {} containers -- starting 10 postgres containers",
count
);
for num in 0..10 {
gs.launch(
&format!("test-{}", num),
bollard::container::Config {
image: Some("postgres:latest".to_string()),
env: Some(vec!["POSTGRES_HOST_AUTH_METHOD=trust".to_string()]),
..Default::default()
},
None,
)
.await?;
}
let newcount = docker
.lock()
.await
.list_containers::<String>(None)
.await
.unwrap()
.len();
println!(
"before: {} containers, after: {} containers -- now dropping",
count, newcount
);
drop(gs);
let newcount = docker
.lock()
.await
.list_containers::<String>(None)
.await
.unwrap()
.len();
println!(
"after dropping: orig: {} containers, after: {} containers",
count, newcount
);
Ok(())
}
作者
Erik Hollensbe [email protected]
许可
BSD 3-Clause
依赖项
~11–22MB
~321K SLoC