summaryrefslogtreecommitdiffstats
path: root/examples/networkdisconnect.rs
blob: 8d58b3536cda340ac0253e640c43c236fbdee4da (plain)
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
use shiplift::{ContainerConnectionOptions, Docker};
use std::env;

async fn network_disconnect(
    container_id: &str,
    network_id: &str,
) {
    let docker = Docker::new();
    let networks = docker.networks();

    if let Err(e) = networks
        .get(network_id)
        .disconnect(&ContainerConnectionOptions::builder(container_id).build())
        .await
    {
        eprintln!("Error: {}", e)
    }
}

#[tokio::main]
async fn main() {
    match (env::args().nth(1), env::args().nth(2)) {
        (Some(container_id), Some(network_id)) => {
            network_disconnect(&container_id, &network_id).await;
        }
        _ => eprintln!("please provide a container_id and network_id"),
    }
}