//! Shiplift is a multi-transport utility for maneuvering [docker](https://www.docker.com/) containers
//!
//! # examples
//!
//! ```no_run
//! # async {
//! let docker = shiplift::Docker::new();
//!
//! match docker.images().list(&Default::default()).await {
//! Ok(images) => {
//! for image in images {
//! println!("{:?}", image.repo_tags);
//! }
//! },
//! Err(e) => eprintln!("Something bad happened! {}", e),
//! }
//! # };
//! ```
pub mod builder;
pub mod errors;
pub mod rep;
pub mod transport;
pub mod tty;
mod tarball;
pub use crate::{
builder::{
BuildOptions, ContainerConnectionOptions, ContainerFilter, ContainerListOptions,
ContainerOptions, EventsOptions, ExecContainerOptions, ImageFilter, ImageListOptions,
LogsOptions, NetworkCreateOptions, NetworkListOptions, PullOptions, RegistryAuth,
RmContainerOptions, TagOptions, VolumeCreateOptions,
},
errors::Error,
};
use crate::{
rep::{
Change, Container as ContainerRep, ContainerCreateInfo, ContainerDetails, Event, Exit,
History, Image as ImageRep, ImageDetails, Info, NetworkCreateInfo,
NetworkDetails as NetworkInfo, SearchResult, Stats, Status, Top, Version,
Volume as VolumeRep, VolumeCreateInfo, Volumes as VolumesRep,
},
transport::{tar, Transport},
tty::Multiplexer as TtyMultiPlexer,
};
use futures_util::{
io::{AsyncRead, AsyncWrite},
stream::Stream,
TryFutureExt, TryStreamExt,
};
// use futures::{future::Either, Future, IntoFuture, Stream};
pub use hyper::Uri;
use hyper::{client::HttpConnector, Body, Client, Method};
#[cfg(feature = "tls")]
use hyper_openssl::HttpsConnector;
#[cfg(feature = "unix-socket")]
use hyperlocal::UnixConnector;
use mime::Mime;
#[cfg(feature = "tls")]
use openssl::ssl::{SslConnector, SslFiletype, SslMethod};
use serde_json::Value;
use std::{borrow::Cow, env, io, io::Read, iter, path::Path, time::Duration};
use url::form_urlencoded;
/// Represents the result of all docker operations
pub type Result<T> = std::result::Result<T, Error>;
/// Entrypoint interface for communicating with docker daemon
#[derive(Clone)]
pub struct Docker {
transport: Transport,
}
/// Interface for accessing and manipulating a named docker image
pub struct Image<'a> {
docker: &'a Docker,
name: Cow<'a, str>,
}
impl<'a> Image<'a> {
/// Exports an interface for operations that may be performed against a named image
pub fn new<S>(
docker: &'a Docker,
name: S,
) -> Self
where
S: Into<Cow<'a, str>>,
{
Image {
docker,
name: name.into(),
}
}
/// Inspects a named image's details
pub async fn inspect(&self) -> Result<ImageDetails> {
self.docker
.get_json(&format!("/images/{}/json", self.name)[..])
.await
}
/// Lists the history of the images set of changes
pub async fn history(&self)