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
pub fn get_host_port(&self, internal_port: u16) -> u16
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 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.IPAddress
pub fn exec(&self, cmd: ExecCommand)
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,
The destructor implementation for a Container.
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.