Struct testcontainers::Container
source · pub struct Container<I: Image> { /* private fields */ }
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,
impl<I> Container<I>where
I: Image,
sourcepub fn image_args(&self) -> &I::Args
pub fn image_args(&self) -> &I::Args
pub fn ports(&self) -> Ports
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
sourcepub fn get_host_ip_address(&self) -> IpAddr
👎Deprecated since 0.16.6: Please use get_host
instead
pub fn get_host_ip_address(&self) -> IpAddr
get_host
insteadReturns the host ip address of docker container
sourcepub fn get_host(&self) -> Host
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