Struct testcontainers::Container

source ·
pub struct Container<I: Image> { /* private fields */ }
Available on crate feature blocking only.
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 container = MyImage::default().start();
    // Docker container is stopped/removed at the end of this scope.
}

Implementations§

source§

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

source

pub fn id(&self) -> &str

Returns the id of this container.

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

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 get_host_ip_address(&self) -> IpAddr

👎Deprecated since 0.16.6: Please use get_host instead

Returns the host ip address of docker container

source

pub fn get_host(&self) -> Host

Returns the host that this container may be reached on (may not be the local machine) Suitable for use in URL

source

pub fn exec(&self, cmd: ExecCommand)

source

pub fn stop(&self)

source

pub fn start(&self)

source

pub fn rm(self)

Trait Implementations§

source§

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

source§

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

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

impl<I: Image> Drop for Container<I>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<I> !Freeze for Container<I>

§

impl<I> !RefUnwindSafe for Container<I>

§

impl<I> Send for Container<I>

§

impl<I> Sync for Container<I>

§

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

§

impl<I> !UnwindSafe for Container<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> 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> IntoResult<T> for T

§

type Err = Infallible

source§

fn into_result(self) -> Result<T, <T as IntoResult<T>>::Err>

source§

impl<T, U> TryFrom<U> for T
where 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 T
where 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.
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