pub struct Container { /* private fields */ }Expand description
A container that exists in Docker, created by CaseScope::create_container.
Implementations§
Source§impl Container
impl Container
Sourcepub async fn existing(
docker: &Docker,
name: &str,
deadline: Instant,
) -> Result<Self, GenericError>
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.
Sourcepub async fn start(&self, deadline: Instant) -> Result<(), GenericError>
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.
Sourcepub async fn published_port(
&self,
port: u16,
deadline: Instant,
) -> Result<u16, GenericError>
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.
Sourcepub async fn status(&self, deadline: Instant) -> Result<Status, GenericError>
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.
Sourcepub async fn wait(&self, deadline: Instant) -> Result<i64, GenericError>
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.
Sourcepub fn logs(&self) -> OutputStream
pub fn logs(&self) -> OutputStream
Follows the container’s output from its start until it exits.
Sourcepub async fn stop(
&self,
grace: Duration,
deadline: Instant,
) -> Result<(), GenericError>
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.
Sourcepub async fn remove(&self, deadline: Instant) -> Result<(), GenericError>
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
impl Container
Sourcepub async fn exec(
&self,
command: Vec<String>,
stdin: Option<Bytes>,
deadline: Instant,
) -> Result<ExecOutput, GenericError>
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.
Sourcepub async fn exec_into<O, E>(
&self,
request: ExecRequest,
stdout: &mut O,
stderr: &mut E,
deadline: Instant,
) -> Result<i64, GenericError>
pub async fn exec_into<O, E>( &self, request: ExecRequest, stdout: &mut O, stderr: &mut E, deadline: Instant, ) -> Result<i64, GenericError>
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
impl Container
Sourcepub async fn place(
&self,
root: &str,
archive: Archive,
deadline: Instant,
) -> Result<(), GenericError>
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.
Sourcepub async fn read_file(
&self,
path: &str,
deadline: Instant,
) -> Result<Option<Vec<u8>>, GenericError>
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.