Coder Social home page Coder Social logo

shiplift's Introduction

shiplift

Build Status crates.io MIT licensed

a rust interface for maneuvering docker containers

install

Add the following to your Cargo.toml file

[dependencies]
shiplift = "0.3"

docs

Find them here.

usage

Some small example programs can be found in this repository's examples directory.

communicating with hosts

To use shiplift, you must first have a docker daemon readily accessible. Typically this daemon processs is resolvable via a url specified by an env var named DOCKER_HOST. If you are using osx, docker-machine typically will have already set up every thing you need to get started when you run docker-machine env {envid}.

extern crate shiplift;
let docker = shiplift::Docker::new();

If you wish to be more explicit you can provide a host in the form of a url.Url.

extern crate shiplift;
extern crate url;

use shiplift::Docker;
use url::Url;

let docker = Docker::host(Url::parse("http://yourhost").unwrap());

images

If you are interacting with docker containers, chances are you will also need to interact with docker image information. You can interact docker images with docker.images().

extern crate shiplift;

use shiplift::Docker;

let docker = Docker.new();
let images = docker.images();

list host-local images

for i in images.list(&Default::default()).unwrap() {
  println!("-> {:?}", i);
}

find remote images

for i in image.search("rust").unwrap() {
  println!("- {:?}", i);
}

creating new image by pulling an existing image

use shiplift::PullOptions;
let output = images.pull(
  &PullOptions::builder().image("redis:2.8.18").build()
).unwrap();
for o in output {
  println!("{:?}", o);
}

build an image from the contents of a directory containing a Dockerfile

the following is equivalent to docker build -t shiplift_test .

use shiplift::BuildOptions;

let output = images.build(
     &BuildOptions::builder(".").tag("shiplift_test").build()
).unwrap();
for o in output {
    println!("{:?}", o);
}

accessing image info

let img = images.get("imagename");
inspecting image info
println!("- {:?}", img.inspect().unwrap());
getting image history
for h in img.history().unwrap() {
  println!("- {:?}", h);
}
deleting image
println!("- {:?}", img.delete().unwrap());

containers

Containers are instances of images. To gain access to this interface use docker.containers()

extern crate shiplift;

use shiplift::Docker;

let docker = Docker.new();
let containers = docker.containers();

listing host local containers

for c in containers.list(&Default::default()).unwrap() {
  println!("- {:?}", c);
}

get a container reference

let container = containers.get("containerid");

inspect container details

println!("- {:?}", container.inspect());

access top info

println!("- {:?}", container.top().unwrap());

view container logs

(todoc)

view a list of container changes

for c in container.changes().unwrap() {
  println!("- {:?}", c);
}

stream container stats

for stats in container.stats().unwrap() {
  println!("- {:?}", stats);
}

stop, start, restart container

container.stop();
container.start();
container.restart();

misc

todoc

roadmap

There are plans on switching from rustc-serialize to serde for serialization in 0.4.0 this should not have major impact on current interfaces.

Doug Tangren (softprops) 2015-2016

shiplift's People

Contributors

softprops avatar gregwebs avatar joxit avatar petehayes102 avatar tshepang avatar blankenshipz avatar akirill0v avatar morsicus avatar shulcsm avatar jagu-sayan avatar abronan avatar pitkley avatar stephanbuys avatar timmartin avatar imamdigmi avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.