Crate contain_rs

Source
Expand description

§contain-rs

A tool to use docker and podman containers with rust.

For usage take a look at the Documentation

§Basic usage

use contain_rs::{Docker, Client, Handle, Container, Image};
use std::str::FromStr;

let podman = Docker::new();

let container = Container::from_image(Image::from_str("docker.io/library/nginx").unwrap());

let handle = podman.create(container);

handle.run();
handle.wait();

// when the handle gets out of scope the container is stopped and removed

§Clients

Clients are used for scheduling containers. There are currently two implementations available. One of them works with docker the other one uses podman.

§Images

Containers need image to run. You can create images like so:

use contain_rs::Image;
use std::str::FromStr;

let image = Image::from_str("docker.io/library/nginx");

assert!(image.is_ok());

let latest = Image::from_str("docker.io/library/nginx:latest");

assert!(latest.is_ok());

§Macro

Contain-rs provides a derive macro to implement the IntoContainer trait for a struct. The macros feature has to be enabled to make use of the derive macro.

You can then create a container like this:

use contain_rs::*;

#[derive(ContainerImpl, Default)]
#[container(
    image = "docker.io/library/nginx",
    health_check_command = "curl http://localhost || exit 1"
)]
struct Nginx {
    #[contain_rs(port = 80)]
    port: u32,
}

let client = Docker::default();

let nginx = client.create(Nginx{ port: 8080 });

nginx.run();
nginx.wait();
nginx.rm(); // stops and removes the container
// this would be done automatically when the container handle goes out of scope

Structs§

Container
A container makes up the schedulable unit of this crate.
ContainerHandle
Docker
The Docker struct is used for acessing the docker cli.
EnvVar
HealthCheck
Image
Podman
The Podman struct is used for acessing the podman cli.
Port
PortMapping
Regex
A compiled regular expression for searching Unicode haystacks.

Enums§

WaitStrategy
A wait strategy can be used to wait for a cotnainer to be ready.

Traits§

Client
The client Trait represents a way to access a client.
Handle
A handle is a way to interact with a container.
IntoContainer