pub struct Container<'d, D, I>{ /* 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:
#[test]
fn a_test() {
let docker = Cli::default();
{
let container = docker.run(MyImage::default());
// Docker container is stopped/removed at the end of this scope.
}
}
Implementations§
Source§impl<'d, D, I> Container<'d, D, I>
impl<'d, D, I> Container<'d, D, I>
Sourcepub fn new(id: String, docker_client: &'d D, image: I) -> Self
👎Deprecated since 0.3.1: Testcontainers is no longer using microcrates, please upgrade to testcontainers version 0.8
pub fn new(id: String, docker_client: &'d D, image: I) -> Self
Constructs a new container given an id, a docker client and the image.
This function will block the current thread (if wait_until_ready
is implemented correctly) until the container is actually ready to be used.
Sourcepub fn id(&self) -> &str
👎Deprecated since 0.3.1: Testcontainers is no longer using microcrates, please upgrade to testcontainers version 0.8
pub fn id(&self) -> &str
Returns the id of this container.
Sourcepub fn logs(&self) -> Logs
👎Deprecated since 0.3.1: Testcontainers is no longer using microcrates, please upgrade to testcontainers version 0.8
pub fn logs(&self) -> Logs
Gives access to the log streams of this container.
Sourcepub fn get_host_port(&self, internal_port: u32) -> Option<u32>
👎Deprecated since 0.3.1: Testcontainers is no longer using microcrates, please upgrade to testcontainers version 0.8
pub fn get_host_port(&self, internal_port: u32) -> Option<u32>
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 image does not expose a port, this method will not be able to resolve it.
Trait Implementations§
Source§impl<'d, D, I> Drop for Container<'d, D, I>
The destructor implementation for a Container.
impl<'d, D, I> Drop for Container<'d, D, I>
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.
This behaviour can be controlled through the KEEP_CONTAINERS
environment variable. Setting it to true
will only stop containers instead of removing them. Any other or no value will remove the container.