bollard
bollard copied to clipboard
Pulling image from Docker Hub.
From reading documentation it seems if an image isn't present on host the library will pull from Docker Hub but this doesn't seem to be happening. Could I be missing something in the below example?
pub fn docker_run_slave(&mut self) {
let mut rt = Runtime::new().unwrap();
let docker = Docker::connect_with_local_defaults().unwrap();
#[cfg(feature = "tls")]
let docker = Docker::connect_with_tls_defaults().unwrap();
let stream = docker
.chain()
.create_image(
Some(CreateImageOptions {
from_image: "confluentinc/cp-kafka:5.0.1",
..Default::default()
}),
None
)
.and_then(move |(docker, _)| {
docker.create_container(
Some(CreateContainerOptions { name: "mc" }),
Config {
image: Some("confluentinc/cp-kafka:5.0.1"),
host_config: Some(HostConfig {
..Default::default()
}),
..Default::default()
},
)
})
.and_then(move |(docker, _)| {
docker.start_container("mc", None::<StartContainerOptions<String>>)
})
.into_stream();
let future = stream
.map_err(|e| println!("{:?}", e))
.for_each(|x| Ok(println!("{:?}", x)));
rt.spawn(future);
rt.shutdown_on_idle().wait().unwrap();
}
The examples in bollard are a little contrived and I apologise, I'll get them fixed. You need to consume the stream that is returned from the create_image
API:
let stream = docker
.chain()
.create_image(
Some(CreateImageOptions {
from_image: "confluentinc/cp-kafka:5.0.1",
..Default::default()
}),
None
).and_then(move |(docker, stream)|
stream.and_then(|l| {
println!("{:?}", l);
Ok(l)
}).collect().map(|_| docker)
)
.and_then(move |(docker, _)| {
// ...
I am still a little new to Rust full power. This is one answer I should have at least considered. Thank you very much for pushing me back on track.
Cheers!