#docker #container #starting

docker-ctl

Crate for conveniently starting and stopping docker containers

4 releases

0.2.2 Nov 28, 2024
0.2.1 Oct 21, 2024
0.2.0 Sep 10, 2024
0.1.0 Sep 6, 2024

#580 in Unix APIs

Download history 239/week @ 2024-09-06 51/week @ 2024-09-13 22/week @ 2024-09-20 15/week @ 2024-09-27 2/week @ 2024-10-04 152/week @ 2024-10-18 16/week @ 2024-10-25 16/week @ 2024-11-01 6/week @ 2024-11-08 6/week @ 2024-11-15 69/week @ 2024-11-22 53/week @ 2024-11-29

136 downloads per month
Used in auksys

MIT license

17KB
446 lines

docs crates.io

docker-ctl

Crate for conveniently starting and stopping docker containers. This crate is a wrapper around the docker command line interface.

Installation

Add docker-ctl to your project with:

cargo add docker-ctl

Example

use docker_ctl::Container;
use std::io::{Read, Write};

// Create a new container, with the `alpine` image in interractive mode.
let mut container = Container::configure("alpine")
  .set_interractive(true)
  .create();

/// Start the container
container.start().unwrap();

/// Run the `echo` command in the container
let mut stdin = container.take_stdin().unwrap();
stdin.write_all(b"echo Hello World!").unwrap();

/// Dropping `stdin` will terminate the container
drop(stdin);

/// Read the output
let mut buf = vec![];
container
  .take_stdout()
  .unwrap()
  .read_to_end(&mut buf)
  .unwrap();

/// Print `Hellow World!\n` characters.
println!("{:?}", buf);

Dependencies

~0.6–26MB
~373K SLoC