File: events.rs

package info (click to toggle)
rust-dockworker 0.7.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 920 kB
  • sloc: makefile: 2
file content (25 lines) | stat: -rw-r--r-- 809 bytes parent folder | download | duplicates (2)
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
use dockworker::{ContainerCreateOptions, Docker};

#[tokio::main]
async fn main() {
    let docker = Docker::connect_with_defaults().unwrap();
    let mut events = docker.events(None, None, None).await.unwrap();

    let create = ContainerCreateOptions::new("hello-world:linux");
    docker.create_image("hello-world", "linux").await.unwrap();
    let container = docker.create_container(None, &create).await.unwrap();
    docker.start_container(&container.id).await.unwrap();

    use futures::stream::StreamExt;
    while let Some(e) = events.next().await {
        let e = e.unwrap();
        if e.Type == "network" && e.Action == "disconnect" {
            println!("{e:?}");
        }
    }

    docker
        .remove_container(&container.id, None, Some(true), None)
        .await
        .unwrap();
}