Skip to main content

ContainerBuilder

Struct ContainerBuilder 

Source
pub struct ContainerBuilder {
    pub stdin: Option<OwnedFd>,
    pub stdout: Option<OwnedFd>,
    pub stderr: Option<OwnedFd>,
    /* private fields */
}

Fields§

§stdin: Option<OwnedFd>§stdout: Option<OwnedFd>§stderr: Option<OwnedFd>

Implementations§

Source§

impl ContainerBuilder

Builder that can be used to configure the common properties of either a init or a tenant container

§Example

use libcontainer::container::builder::ContainerBuilder;
use libcontainer::syscall::syscall::SyscallType;

ContainerBuilder::new(
    "74f1a4cb3801".to_owned(),
    SyscallType::default(),
)
.with_root_path("/run/containers/youki").expect("invalid root path")
.with_pid_file(Some("/var/run/docker.pid")).expect("invalid pid file")
.with_console_socket(Some("/var/run/docker/sock.tty"))
.as_init("/var/run/docker/bundle")
.build();
Source

pub fn new(container_id: String, syscall: SyscallType) -> Self

Generates the base configuration for a container which can be transformed into either a init container or a tenant container

§Example
use libcontainer::container::builder::ContainerBuilder;
use libcontainer::syscall::syscall::SyscallType;

let builder = ContainerBuilder::new(
    "74f1a4cb3801".to_owned(),
    SyscallType::default(),
);
Source

pub fn validate_id(self) -> Result<Self, LibcontainerError>

validate_id checks if the supplied container ID is valid, returning the ErrInvalidID in case it is not.

The format of valid ID was never formally defined, instead the code was modified to allow or disallow specific characters.

Currently, a valid ID is a non-empty string consisting only of the following characters:

  • uppercase (A-Z) and lowercase (a-z) Latin letters;
  • digits (0-9);
  • underscore (_);
  • plus sign (+);
  • minus sign (-);
  • period (.).

In addition, IDs that can’t be used to represent a file name (such as . or ..) are rejected.

Source

pub fn as_tenant(self) -> TenantContainerBuilder

Transforms this builder into a tenant builder

§Example

ContainerBuilder::new(
    "74f1a4cb3801".to_owned(),
    SyscallType::default(),
)
.as_tenant()
.with_container_args(vec!["sleep".to_owned(), "9001".to_owned()])
.build();
Source

pub fn as_init<P: Into<PathBuf>>(self, bundle: P) -> InitContainerBuilder

Transforms this builder into an init builder

§Example

ContainerBuilder::new(
    "74f1a4cb3801".to_owned(),
    SyscallType::default(),
)
.as_init("/var/run/docker/bundle")
.with_systemd(false)
.build();
Source

pub fn with_root_path<P: Into<PathBuf>>( self, path: P, ) -> Result<Self, LibcontainerError>

Sets the root path which will be used to store the container state

§Example

ContainerBuilder::new(
    "74f1a4cb3801".to_owned(),
    SyscallType::default(),
)
.with_root_path("/run/containers/youki").expect("invalid root path");
Source

pub fn with_pid_file<P: Into<PathBuf>>( self, path: Option<P>, ) -> Result<Self, LibcontainerError>

Sets the pid file which will be used to write the pid of the container process

§Example

ContainerBuilder::new(
    "74f1a4cb3801".to_owned(),
    SyscallType::default(),
)
.with_pid_file(Some("/var/run/docker.pid")).expect("invalid pid file");
Source

pub fn with_console_socket<P: Into<PathBuf>>(self, path: Option<P>) -> Self

Sets the console socket, which will be used to send the file descriptor of the pseudoterminal

§Example

ContainerBuilder::new(
    "74f1a4cb3801".to_owned(),
    SyscallType::default(),
)
.with_console_socket(Some("/var/run/docker/sock.tty"));
Source

pub fn with_preserved_fds(self, preserved_fds: i32) -> Self

Sets the number of additional file descriptors which will be passed into the container process.

§Example

ContainerBuilder::new(
    "74f1a4cb3801".to_owned(),
    SyscallType::default(),
)
.with_preserved_fds(5);
Source

pub fn with_executor(self, executor: impl Executor + 'static) -> Self

Sets the function that actually runs on the container init process.

§Example

ContainerBuilder::new(
    "74f1a4cb3801".to_owned(),
    SyscallType::default(),
)
.with_executor(DefaultExecutor{});
Source

pub fn with_stdin(self, stdin: impl Into<OwnedFd>) -> Self

Sets the stdin of the container, for those who use libcontainer as a library, the container stdin may have to be set to an opened file descriptor rather than the stdin of the current process.

§Example

let (r, _w) = pipe().unwrap();
ContainerBuilder::new(
    "74f1a4cb3801".to_owned(),
    SyscallType::default(),
)
.with_stdin(r);
Source

pub fn with_stdout(self, stdout: impl Into<OwnedFd>) -> Self

Sets the stdout of the container, for those who use libcontainer as a library, the container stdout may have to be set to an opened file descriptor rather than the stdout of the current process.

§Example

let (_r, w) = pipe().unwrap();
ContainerBuilder::new(
    "74f1a4cb3801".to_owned(),
    SyscallType::default(),
)
.with_stdout(w);
Source

pub fn with_stderr(self, stderr: impl Into<OwnedFd>) -> Self

Sets the stderr of the container, for those who use libcontainer as a library, the container stderr may have to be set to an opened file descriptor rather than the stderr of the current process.

§Example

let (_r, w) = pipe().unwrap();
ContainerBuilder::new(
    "74f1a4cb3801".to_owned(),
    SyscallType::default(),
)
.with_stderr(w);

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more