I can use shiplift to get a list of the running containers but I have found it very difficult to stop them. After much trial and error, it seems I can create a vector of futures and then join them all in order to create a single future to return. This joined future does not seem to be called and the containers are never stopped. Is there a better way to run all these futures and then return the result?
let docker = connection.clone();
docker
.containers()
.list(&Default::default())
.map(move |list| {
let mut futures = Vec::new();
for container in list {
let cont = connection.containers().get(&container.id);
println!("Stopping {}", cont.id());
futures.push(cont.stop(Some(std::time::Duration::from_secs(1))));
// futures.push(connection.containers().get(&container.id).stop(None).map_err(|_| println!("error")));
}
join_all(futures)
})
.map(|_| println!("Stopped all"))
.map_err(|e| eprintln!("Error: {}", e))