Struct Container

Source
pub struct Container<'d, D, I>
where D: 'd + Docker, I: Image,
{ /* private fields */ }
👎Deprecated since 0.3.1: Testcontainers is no longer using microcrates, please upgrade to testcontainers version 0.8
Expand description

Represents a running docker container.

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

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

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

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

Implementations§

Source§

impl<'d, D, I> Container<'d, D, I>
where D: Docker, I: Image,

Source

pub fn new(id: String, docker_client: &'d D, image: I) -> Self

👎Deprecated since 0.3.1: Testcontainers is no longer using microcrates, please upgrade to testcontainers version 0.8

Constructs a new container given an id, a docker client and the image.

This function will block the current thread (if wait_until_ready is implemented correctly) until the container is actually ready to be used.

Source

pub fn id(&self) -> &str

👎Deprecated since 0.3.1: Testcontainers is no longer using microcrates, please upgrade to testcontainers version 0.8

Returns the id of this container.

Source

pub fn logs(&self) -> Logs

👎Deprecated since 0.3.1: Testcontainers is no longer using microcrates, please upgrade to testcontainers version 0.8

Gives access to the log streams of this container.

Source

pub fn get_host_port(&self, internal_port: u32) -> Option<u32>

👎Deprecated since 0.3.1: Testcontainers is no longer using microcrates, please upgrade to testcontainers version 0.8

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 image does not expose a port, this method will not be able to resolve it.

Source

pub fn image(&self) -> &I

👎Deprecated since 0.3.1: Testcontainers is no longer using microcrates, please upgrade to testcontainers version 0.8

Returns a reference to the Image of this container.

Access to this is useful if the arguments of the Image change how to connect to the Access to this is useful to retrieve Image specific information such as authentication details or other relevant information which have been passed as arguments

Trait Implementations§

Source§

impl<'d, D, I> Debug for Container<'d, D, I>
where D: 'd + Docker + Debug, I: Image + Debug,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'d, D, I> Drop for Container<'d, D, I>
where D: Docker, I: Image,

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. This behaviour can be controlled through the KEEP_CONTAINERS environment variable. Setting it to true will only stop containers instead of removing them. Any other or no value will remove the container.

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'d, D, I> Freeze for Container<'d, D, I>
where I: Freeze,

§

impl<'d, D, I> RefUnwindSafe for Container<'d, D, I>

§

impl<'d, D, I> Send for Container<'d, D, I>
where I: Send, D: Sync,

§

impl<'d, D, I> Sync for Container<'d, D, I>
where I: Sync, D: Sync,

§

impl<'d, D, I> Unpin for Container<'d, D, I>
where I: Unpin,

§

impl<'d, D, I> UnwindSafe for Container<'d, D, I>

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