forked from fussybeaver/bollard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
info.rs
49 lines (40 loc) · 1.26 KB
/
info.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//! Fetch info of all running containers concurrently
use bollard::container::{InspectContainerOptions, ListContainersOptions};
use bollard::models::ContainerSummary;
use bollard::Docker;
use std::collections::HashMap;
use std::default::Default;
use futures_util::stream;
use futures_util::stream::StreamExt;
async fn conc(arg: (Docker, &ContainerSummary)) {
let (docker, container) = arg;
println!(
"{:?}",
docker
.inspect_container(
container.id.as_ref().unwrap(),
None::<InspectContainerOptions>
)
.await
.unwrap()
)
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + 'static>> {
let docker = Docker::connect_with_socket_defaults().unwrap();
let mut list_container_filters = HashMap::new();
list_container_filters.insert("status", vec!["running"]);
let containers = &docker
.list_containers(Some(ListContainersOptions {
all: true,
filters: list_container_filters,
..Default::default()
}))
.await?;
let docker_stream = stream::repeat(docker);
docker_stream
.zip(stream::iter(containers))
.for_each_concurrent(2, conc)
.await;
Ok(())
}