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§

source§

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

source

pub fn image(&self) -> &I

Returns a reference to the Image of this container.

source

pub fn image_args(&self) -> &I::Args

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

source

pub fn ports(&self) -> Ports

source§

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

source

pub fn id(&self) -> &str

Returns the id of this container.

source

pub fn get_host_port(&self, internal_port: u16) -> u16

👎Deprecated since 0.13.1: Use get_host_port_ipv4() or get_host_port_ipv6() instead.

Returns the mapped host port for an internal port of this docker container, on the host’s IPv4 interfaces.

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.

source

pub fn get_host_port_ipv4(&self, internal_port: u16) -> u16

Returns the mapped host port for an internal port of this docker container, on the host’s IPv4 interfaces.

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.

source

pub fn get_host_port_ipv6(&self, internal_port: u16) -> u16

Returns the mapped host port for an internal port of this docker container, on the host’s IPv6 interfaces.

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.

source

pub fn get_bridge_ip_address(&self) -> IpAddr

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

source

pub fn exec(&self, cmd: ExecCommand) -> ExecOutput

source

pub fn stop(&self)

source

pub fn start(&self)

source

pub fn rm(&self)

Trait Implementations§

source§

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

source§

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

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

impl<'d, I> Drop for Container<'d, I>where 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, depending on the Command value.

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

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

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

§

impl<'d, I> Send for Container<'d, I>where I: Send, <I as Image>::Args: Send,

§

impl<'d, I> Sync for Container<'d, I>where I: Sync, <I as Image>::Args: Sync,

§

impl<'d, I> Unpin for Container<'d, I>where I: Unpin, <I as Image>::Args: Unpin,

§

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

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.