-
-
Notifications
You must be signed in to change notification settings - Fork 118
/
Copy pathimagepull_auth.rs
31 lines (27 loc) · 928 Bytes
/
imagepull_auth.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
// cargo run --example imagepull_auth busybox username password
use futures::StreamExt;
use shiplift::{Docker, PullOptions, RegistryAuth};
use std::env;
#[tokio::main]
async fn main() {
env_logger::init();
let docker = Docker::new();
let img = env::args()
.nth(1)
.expect("You need to specify an image name");
let username = env::args().nth(2).expect("You need to specify an username");
let password = env::args().nth(3).expect("You need to specify a password");
let auth = RegistryAuth::builder()
.username(username)
.password(password)
.build();
let mut stream = docker
.images()
.pull(&PullOptions::builder().image(img).auth(auth).build());
while let Some(pull_result) = stream.next().await {
match pull_result {
Ok(output) => println!("{:?}", output),
Err(e) => eprintln!("{}", e),
}
}
}