Struct testcontainers::core::Container
source · 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,
impl<'d, I> Container<'d, I>where I: Image,
sourcepub fn image_args(&self) -> &I::Args
pub fn image_args(&self) -> &I::Args
pub fn ports(&self) -> Ports
source§impl<'d, I> Container<'d, I>where
I: Image,
impl<'d, I> Container<'d, I>where I: Image,
sourcepub 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.
pub fn get_host_port(&self, internal_port: u16) -> u16
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.
sourcepub fn get_host_port_ipv4(&self, internal_port: u16) -> u16
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.
sourcepub fn get_host_port_ipv6(&self, internal_port: u16) -> u16
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.
sourcepub fn get_bridge_ip_address(&self) -> IpAddr
pub fn get_bridge_ip_address(&self) -> IpAddr
Returns the bridge ip address of docker container as specified in NetworkSettings.Networks.IPAddress
pub fn exec(&self, cmd: ExecCommand) -> ExecOutput
pub fn stop(&self)
pub fn start(&self)
pub fn rm(&self)
Trait Implementations§
source§impl<'d, I> Drop for Container<'d, I>where
I: Image,
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.