Giter VIP home page Giter VIP logo

docker-rust's Introduction

#Docker-Rust (WIP)

A client library for the Docker Remote API written in Rust.
Currently targetting API v1.12+

A lot of functionality is currently on hold until Rust's HTTP and JSON libs are up to snuff.

Run Tests

make test

Use

Declare cargo dependency in your Cargo.toml

[dependencies.docker]

git = "https://github.com/abh1nav/docker-rust.git"

Features

Get a list of running containers

extern crate docker;

use docker::Docker;

// Currently only works if docker is run using a unix socket (the default)
let client: Docker = Docker {
	socket_path: "/var/run/docker.sock"
};
  
// common::containers::Containers is a Vec<common::containers::Container>
let containers: Containers = client.get_containers();
  
println!("Running container count: {}", containers.len());

Restart, stop and remove a container

let container_id = "5fc6a1226f01".to_string();

// Restart container
client.restart_container(container_id.as_slice());
// OR wait 3 seconds for the container to stop before forcing restart
client.restart_container_with_timeout(container_id.as_slice(), 3);

// Stop the container
client.stop_container(container_id.as_slice());
// OR wait 3 seconds for the container to stop before killing
client.stop_container_with_timeout(container_id.as_slice(), 3);

// Remove the container and its volumes
client.remove_container(container_id.as_slice());
// OR remove with the force flag
client.remove_container_with_force(container_id.as_slice());

Get a list of Images

// common::images::Images is a Vec<common::images::Image>
let images: Images = client.get_images();
  
println!("Image count: {}", images.len());

Utility endpoints

// Get system info -> common::sys_info::SysInfo
let sys_info = client.get_sys_info();
println!("Number of containers: {}\nNumber of Images: {}", sys_info.Containers, sys_info.Images);

// Get docker version -> common::version::Version
let version = client.get_version();
println!("Docker version: {}", version.Version);

docker-rust's People

Contributors

abh1nav 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.