pub struct Container<'d, I: Image> { /* private fields */ }
Expand description

Represents a running docker container.

Containers have a custom destructor that removes them as soon as they go out of scope:

use testcontainers::*;
#[test]
fn a_test() {
    let docker = clients::Cli::default();

    {
        let container = docker.run(MyImage::default());

        // Docker container is stopped/removed at the end of this scope.
    }
}

Implementations

Returns a reference to the Image of this container.

Returns a reference to the arguments of the Image of this container.

Access to this is useful to retrieve relevant information which had been passed as arguments

Returns the id of this container.

Returns the mapped host port for an internal port of this docker container.

This method does not magically expose the given port, it simply performs a mapping on the already exposed ports. If a docker container does not expose a port, this method will panic.

Panics

This method panics if the given port is not mapped. Testcontainers is designed to be used in tests only. If a certain port is not mapped, the container is unlikely to be useful.

Returns the bridge ip address of docker container as specified in NetworkSettings.IPAddress

Trait Implementations

Formats the value using the given formatter. Read more

The destructor implementation for a Container.

As soon as the container goes out of scope, the destructor will either only stop or delete the docker container, depending on the Command value.

Setting it to keep will stop container. Setting it to remove will remove it.

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.