//! Shiplift is a multi-transport utility for maneuvering [docker](https://www.docker.com/) containers
//!
//! # examples
//!
//! ```no_run
//! extern crate shiplift;
//! extern crate tokio;
//!
//! 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);
//! ```
#[macro_use]
extern crate log;
extern crate byteorder;
extern crate bytes;
extern crate flate2;
extern crate futures;
extern crate http;
extern crate hyper;
extern crate hyper_openssl;
#[cfg(feature = "unix-socket")]
extern crate hyperlocal;
extern crate mime;
extern crate openssl;
extern crate tar;
extern crate url;
#[macro_use]
extern crate serde_derive;
extern crate serde;
#[macro_use]
extern crate serde_json;
extern crate tokio;
extern crate tokio_codec;
extern crate tokio_io;
pub mod builder;
pub mod errors;
pub mod read;
pub mod rep;
pub mod transport;
pub mod tty;
mod tarball;
pub use builder::{
BuildOptions, ContainerConnectionOptions, ContainerFilter, ContainerListOptions,
ContainerOptions, EventsOptions, ExecContainerOptions, ImageFilter, ImageListOptions,
LogsOptions, NetworkCreateOptions, NetworkListOptions, PullOptions, RmContainerOptions,
VolumeCreateOptions,
};
pub use errors::Error;
use futures::{future::Either, Future, IntoFuture, Stream};
use hyper::client::HttpConnector;
use hyper::Body;
use hyper::{Client, Method, Uri};
use hyper_openssl::HttpsConnector;
#[cfg(feature = "unix-socket")]
use hyperlocal::UnixConnector;
use mime::Mime;
use openssl::ssl::{SslConnector, SslFiletype, SslMethod};
use read::StreamReader;
use 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,
};
use serde_json::Value;
use std::borrow::Cow;
use std::env;
use std::path::Path;
use std::time::Duration;
use tokio_codec::{FramedRead, LinesCodec};
use transport::{tar, Transport};
use tty::TtyDecoder;
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>>(&format!("/images/{}", self.name)[..])
}
/// Export this image to a tarball
pub fn export(&self) -> impl Stream<Item = Vec<u8>, Error = Error> {