Crates.io | docker-ctl |
lib.rs | docker-ctl |
version | 0.2.1 |
source | src |
created_at | 2024-09-06 19:19:01.392538 |
updated_at | 2024-10-21 06:00:33.140738 |
description | Crate for conveniently starting and stopping docker containers. |
homepage | https://gitlab.com/cyloncore/docker_ctl |
repository | https://github.com/cyloncore/docker_ctl |
max_upload_size | |
id | 1366358 |
size | 16,152 |
Crate for conveniently starting and stopping docker containers. This crate is a wrapper around the docker command line interface.
Add docker-ctl
to your project with:
cargo add docker-ctl
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);