Skip to main content

Container

Struct Container 

Source
pub struct Container { /* private fields */ }
Expand description

A container that exists in Docker, created by CaseScope::create_container.

Implementations§

Source§

impl Container

Source

pub async fn existing( docker: &Docker, name: &str, deadline: Instant, ) -> Result<Self, GenericError>

Opens the container Docker already has under name, which belongs to no case scope: it has no case network, so Self::status reports no address.

§Errors

Returns an error if Docker has no such container, or if deadline passes first.

Source

pub fn name(&self) -> &str

Returns the container’s name.

Source

pub fn id(&self) -> &str

Returns the ID Docker gave the container.

Source

pub async fn start(&self, deadline: Instant) -> Result<(), GenericError>

Starts the container.

§Errors

Returns an error if Docker cannot start the container, for example because its command does not exist, or if deadline passes first.

Source

pub async fn published_port( &self, port: u16, deadline: Instant, ) -> Result<u16, GenericError>

Returns the host port Docker chose for the published TCP port. Call it after Self::start.

§Errors

Returns an error if inspecting the container fails, if Docker reports no binding of port on 127.0.0.1, or if deadline passes first.

Source

pub async fn status(&self, deadline: Instant) -> Result<Status, GenericError>

Returns whether the container is running, with its address and published ports. Call it after Self::start.

§Errors

Returns an error if inspecting the container fails, or if deadline passes first.

Source

pub async fn wait(&self, deadline: Instant) -> Result<i64, GenericError>

Waits for the container to stop running and returns its exit code. Call it after Self::start.

Death by signal n is reported as code 128 + n.

§Errors

Returns an error if Docker cannot report the exit, for example because the container was removed, if the container never ran, because it was not started or its start failed, or if deadline passes before the container exits.

Source

pub fn logs(&self) -> OutputStream

Follows the container’s output from its start until it exits.

Source

pub async fn stop( &self, grace: Duration, deadline: Instant, ) -> Result<(), GenericError>

Stops the container: signals its main process, then kills it if it is still running after grace.

Docker counts the grace in whole seconds, so a fraction of a second is rounded up.

A container that is already stopped or gone counts as stopped.

§Errors

Returns an error if Docker fails to stop the container, or if deadline passes first.

Source

pub async fn remove(&self, deadline: Instant) -> Result<(), GenericError>

Force-removes the container and its anonymous volumes, killing it if it is running. A container that is already gone counts as removed.

§Errors

Returns an error if Docker fails to remove the container, or if deadline passes first.

Source§

impl Container

Source

pub async fn exec( &self, command: Vec<String>, stdin: Option<Bytes>, deadline: Instant, ) -> Result<ExecOutput, GenericError>

Runs command in the running container and waits for it to exit.

With stdin, the bytes are written to the command’s standard input, which is then closed. The command may exit without reading them all. Without it, the command has no standard input. A nonzero exit code is a result, not an error.

§Errors

Returns an error if Docker cannot run the command, if its output cannot be read, if Docker does not report its exit code, or if deadline passes before the command exits.

Source

pub async fn exec_into<O, E>( &self, request: ExecRequest, stdout: &mut O, stderr: &mut E, deadline: Instant, ) -> Result<i64, GenericError>
where O: AsyncWrite + Unpin + ?Sized, E: AsyncWrite + Unpin + ?Sized,

Runs request in the running container, writes its output to stdout and stderr as it arrives, and returns its exit code once it exits.

A nonzero exit code is a result, not an error.

§Errors

Returns an error if Docker cannot run the command, if its output cannot be read or written, if Docker does not report its exit code, or if deadline passes before the command exits.

Source§

impl Container

Source

pub async fn place( &self, root: &str, archive: Archive, deadline: Instant, ) -> Result<(), GenericError>

Places every file of archive under root, such as /, in the container’s filesystem.

This works whether or not the container is running, so files can be placed between create and start. A file whose path lies on a volume the container mounts is written to that volume.

§Errors

Returns an error if the archive cannot be finished, if Docker refuses to extract it, or if deadline passes first.

Source

pub async fn read_file( &self, path: &str, deadline: Instant, ) -> Result<Option<Vec<u8>>, GenericError>

Reads the file at path in the container’s filesystem, or returns None if nothing is there.

§Errors

Returns an error if the container does not exist, if Docker cannot copy the path out, if the path is not a regular file, or if deadline passes first.

Trait Implementations§

Source§

impl Clone for Container

Source§

fn clone(&self) -> Container

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Container

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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