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
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();Sourcepub fn new(container_id: String, syscall: SyscallType) -> Self
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(),
);Sourcepub fn validate_id(self) -> Result<Self, LibcontainerError>
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.
Sourcepub fn as_tenant(self) -> TenantContainerBuilder
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();Sourcepub fn as_init<P: Into<PathBuf>>(self, bundle: P) -> InitContainerBuilder
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();Sourcepub fn with_root_path<P: Into<PathBuf>>(
self,
path: P,
) -> Result<Self, LibcontainerError>
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");Sourcepub fn with_pid_file<P: Into<PathBuf>>(
self,
path: Option<P>,
) -> Result<Self, LibcontainerError>
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");Sourcepub fn with_console_socket<P: Into<PathBuf>>(self, path: Option<P>) -> Self
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"));Sourcepub fn with_preserved_fds(self, preserved_fds: i32) -> Self
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);Sourcepub fn with_executor(self, executor: impl Executor + 'static) -> Self
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{});Sourcepub fn with_stdin(self, stdin: impl Into<OwnedFd>) -> Self
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);Sourcepub fn with_stdout(self, stdout: impl Into<OwnedFd>) -> Self
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);Sourcepub fn with_stderr(self, stderr: impl Into<OwnedFd>) -> Self
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§
impl Freeze for ContainerBuilder
impl !RefUnwindSafe for ContainerBuilder
impl !Send for ContainerBuilder
impl !Sync for ContainerBuilder
impl Unpin for ContainerBuilder
impl UnsafeUnpin for ContainerBuilder
impl !UnwindSafe for ContainerBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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