ContainerBuilder

Struct ContainerBuilder 

Source
pub struct ContainerBuilder<'a> { /* private fields */ }
Expand description

Builder for creating containers with a fluent API.

Implementations§

Source§

impl<'a> ContainerBuilder<'a>

Source

pub fn name(self, name: impl Into<String>) -> Self

Set the container name.

Source

pub fn env(self, key: impl Into<String>, value: impl Into<String>) -> Self

Add an environment variable.

§Example
client.containers()
    .create("nginx:latest")
    .env("ENV", "production")
    .env("DEBUG", "false")
    .build()
    .await?;
Source

pub fn port(self, host_port: u16, container_port: u16, protocol: &str) -> Self

Map a port from host to container.

§Arguments
  • host_port - Port on the host
  • container_port - Port in the container
  • protocol - Protocol (“tcp” or “udp”)
§Example
client.containers()
    .create("nginx:latest")
    .port(8080, 80, "tcp")
    .port(8443, 443, "tcp")
    .build()
    .await?;
Source

pub fn volume( self, host_path: impl Into<String>, container_path: impl Into<String>, ) -> Self

Mount a volume.

§Arguments
  • host_path - Path on the host
  • container_path - Path in the container
§Example
client.containers()
    .create("nginx:latest")
    .volume("/host/data", "/app/data")
    .build()
    .await?;
Source

pub fn network(self, network: impl Into<String>) -> Self

Connect to a network.

Source

pub fn cmd(self, cmd: Vec<impl Into<String>>) -> Self

Set the command to run in the container.

§Example
client.containers()
    .create("alpine:latest")
    .cmd(vec!["echo", "hello"])
    .build()
    .await?;
Source

pub fn entrypoint(self, entrypoint: Vec<impl Into<String>>) -> Self

Set the entrypoint.

Source

pub fn working_dir(self, dir: impl Into<String>) -> Self

Set the working directory.

Source

pub fn restart_always(self) -> Self

Set the restart policy to “always”.

Source

pub fn restart_unless_stopped(self) -> Self

Set the restart policy to “unless-stopped”.

Source

pub fn restart_on_failure(self, max_retries: Option<i64>) -> Self

Set the restart policy to “on-failure” with optional retry count.

Source

pub fn memory(self, bytes: i64) -> Self

Set memory limit in bytes.

Source

pub fn cpu_shares(self, shares: i64) -> Self

Set CPU shares (relative weight).

Source

pub fn label(self, key: impl Into<String>, value: impl Into<String>) -> Self

Add a label.

Source

pub fn auto_remove(self, enable: bool) -> Self

Enable auto-remove (container is deleted when it stops).

Source

pub fn privileged(self, enable: bool) -> Self

Enable privileged mode.

Source

pub async fn build(self) -> Result<ContainerRef<'a>>

Build and create the container.

Returns a ContainerRef that can be used to interact with the container.

Auto Trait Implementations§

§

impl<'a> Freeze for ContainerBuilder<'a>

§

impl<'a> !RefUnwindSafe for ContainerBuilder<'a>

§

impl<'a> Send for ContainerBuilder<'a>

§

impl<'a> Sync for ContainerBuilder<'a>

§

impl<'a> Unpin for ContainerBuilder<'a>

§

impl<'a> !UnwindSafe for ContainerBuilder<'a>

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, 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