pub struct ContainerAsync<I: Image> { /* private fields */ }
Expand description
Represents a running docker container that has been started using an async client.
Containers have a custom destructor
that removes them as soon as they
go out of scope. However, async drop is not available in rust yet. This implementation
is using block_on.
use testcontainers::*;
#[tokio::test]
async fn a_test() {
let container = MyImage::default().start().await.unwrap();
// Docker container is stopped/removed at the end of this scope.
}
Implementations§
Source§impl<I> ContainerAsync<I>where
I: Image,
impl<I> ContainerAsync<I>where
I: Image,
pub async fn ports(&self) -> Result<Ports>
Sourcepub async fn get_host_port_ipv4(
&self,
internal_port: impl Into<ContainerPort>,
) -> Result<u16>
pub async fn get_host_port_ipv4( &self, internal_port: impl Into<ContainerPort>, ) -> Result<u16>
Returns the mapped host port for an internal port of this docker container, on the host’s IPv4 interfaces.
By default, u16
is considered as TCP port. Also, you can convert u16
to ContainerPort
port
by using crate::core::IntoContainerPort
trait.
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 return an error.
Sourcepub async fn get_host_port_ipv6(
&self,
internal_port: impl Into<ContainerPort>,
) -> Result<u16>
pub async fn get_host_port_ipv6( &self, internal_port: impl Into<ContainerPort>, ) -> Result<u16>
Returns the mapped host port for an internal port of this docker container, on the host’s IPv6 interfaces.
By default, u16
is considered as TCP port. Also, you can convert u16
to ContainerPort
port
by using crate::core::IntoContainerPort
trait.
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 return an error.
Sourcepub async fn get_bridge_ip_address(&self) -> Result<IpAddr>
pub async fn get_bridge_ip_address(&self) -> Result<IpAddr>
Returns the bridge ip address of docker container as specified in NetworkSettings.Networks.IPAddress
Sourcepub async fn get_host(&self) -> Result<Host>
pub async fn get_host(&self) -> Result<Host>
Returns the host that this container may be reached on (may not be the local machine) Suitable for use in URL
Sourcepub async fn exec(&self, cmd: ExecCommand) -> Result<ExecResult>
pub async fn exec(&self, cmd: ExecCommand) -> Result<ExecResult>
Executes a command in the container.
Sourcepub fn stdout(&self, follow: bool) -> Pin<Box<dyn AsyncBufRead + Send>>
pub fn stdout(&self, follow: bool) -> Pin<Box<dyn AsyncBufRead + Send>>
Returns an asynchronous reader for stdout.
Accepts a boolean parameter to follow the logs:
- pass
true
to read logs from the moment the container starts until it stops (returns I/O error with kindUnexpectedEof
if container removed). - pass
false
to read logs from startup to present.
Sourcepub fn stderr(&self, follow: bool) -> Pin<Box<dyn AsyncBufRead + Send>>
pub fn stderr(&self, follow: bool) -> Pin<Box<dyn AsyncBufRead + Send>>
Returns an asynchronous reader for stderr.
Accepts a boolean parameter to follow the logs:
- pass
true
to read logs from the moment the container starts until it stops (returns I/O error withUnexpectedEof
if container removed). - pass
false
to read logs from startup to present.
Sourcepub async fn stdout_to_vec(&self) -> Result<Vec<u8>>
pub async fn stdout_to_vec(&self) -> Result<Vec<u8>>
Returns stdout as a vector of bytes available at the moment of call (from container startup to present).
If you want to read stdout in asynchronous manner, use ContainerAsync::stdout
instead.
Sourcepub async fn stderr_to_vec(&self) -> Result<Vec<u8>>
pub async fn stderr_to_vec(&self) -> Result<Vec<u8>>
Returns stderr as a vector of bytes available at the moment of call (from container startup to present).
If you want to read stderr in asynchronous manner, use ContainerAsync::stderr
instead.
Trait Implementations§
Source§impl<I> Debug for ContainerAsync<I>
impl<I> Debug for ContainerAsync<I>
Auto Trait Implementations§
impl<I> Freeze for ContainerAsync<I>where
I: Freeze,
impl<I> !RefUnwindSafe for ContainerAsync<I>
impl<I> Send for ContainerAsync<I>
impl<I> Sync for ContainerAsync<I>
impl<I> Unpin for ContainerAsync<I>where
I: Unpin,
impl<I> !UnwindSafe for ContainerAsync<I>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more