//! Shiplift is a multi-transport utility for maneuvering [docker](https://www.docker.com/) containers
//!
//! # examples
//!
//! ```no_run
//! use tokio::prelude::Future;
//!
//! let docker = shiplift::Docker::new();
//! let fut = docker.images().list(&Default::default()).map(|images| {
//! println!("docker images in stock");
//! for i in images {
//! println!("{:?}", i.repo_tags);
//! }
//! }).map_err(|e| eprintln!("Something bad happened! {}", e));
//!
//! tokio::run(fut);
//! ```
pub mod builder;
pub mod errors;
pub mod read;
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, VolumeCreateOptions,
},
errors::Error,
};
use crate::{
read::StreamReader,
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::TtyDecoder,
};
use futures::{future::Either, Future, IntoFuture, Stream};
use hyper::{client::HttpConnector, Body, Client, Method, Uri};
#[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::Read, iter, path::Path, time::Duration};
use tokio_codec::{FramedRead, LinesCodec};
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, 'b> {
docker: &'a Docker,
name: Cow<'b, str>,
}
impl<'a, 'b> Image<'a, 'b> {
/// Exports an interface for operations that may be performed against a named image
pub fn new<S>(
docker: &'a Docker,
name: S,
) -> Image<'a, 'b>
where
S: Into<Cow<'b, str>>,
{
Image {
docker,
name: name.into(),
}
}
/// Inspects a named image's details
pub fn inspect(&self) -> impl Future<Item = ImageDetails, Error = Error> {
self.docker
.get_json(&format!("/images/{}/json", self.name)[..])
}
/// Lists the history of the images set of changes
pub fn history(&self) -> impl Future<Item = Vec<History>, Error = Error> {
self.docker
.get_json(&format!("/images/{}/history", self.name)[..])
}
/// Deletes an image
pub fn delete(&self) -> impl Future<Item = Vec<Status>, Error = Error> {
self.docker
.delete_json::<Vec<Status>>(