pub trait ImageExt<I>where
I: Image,{
Show 22 methods
// Required methods
fn with_cmd(
self,
cmd: impl IntoIterator<Item = impl Into<String>>,
) -> ContainerRequest<I>;
fn with_name(self, name: impl Into<String>) -> ContainerRequest<I>;
fn with_tag(self, tag: impl Into<String>) -> ContainerRequest<I>;
fn with_container_name(self, name: impl Into<String>) -> ContainerRequest<I>;
fn with_network(self, network: impl Into<String>) -> ContainerRequest<I>;
fn with_label(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> ContainerRequest<I>;
fn with_labels(
self,
labels: impl IntoIterator<Item = (impl Into<String>, impl Into<String>)>,
) -> ContainerRequest<I>;
fn with_env_var(
self,
name: impl Into<String>,
value: impl Into<String>,
) -> ContainerRequest<I>;
fn with_host(
self,
key: impl Into<String>,
value: impl Into<Host>,
) -> ContainerRequest<I>;
fn with_mount(self, mount: impl Into<Mount>) -> ContainerRequest<I>;
fn with_copy_to(
self,
target: impl Into<String>,
source: impl Into<CopyDataSource>,
) -> ContainerRequest<I>;
fn with_mapped_port(
self,
host_port: u16,
container_port: ContainerPort,
) -> ContainerRequest<I>;
fn with_ulimit(
self,
name: &str,
soft: i64,
hard: Option<i64>,
) -> ContainerRequest<I>;
fn with_privileged(self, privileged: bool) -> ContainerRequest<I>;
fn with_cap_add(self, capability: impl Into<String>) -> ContainerRequest<I>;
fn with_cap_drop(self, capability: impl Into<String>) -> ContainerRequest<I>;
fn with_cgroupns_mode(
self,
cgroupns_mode: CgroupnsMode,
) -> ContainerRequest<I>;
fn with_userns_mode(self, userns_mode: &str) -> ContainerRequest<I>;
fn with_shm_size(self, bytes: u64) -> ContainerRequest<I>;
fn with_startup_timeout(self, timeout: Duration) -> ContainerRequest<I>;
fn with_working_dir(
self,
working_dir: impl Into<String>,
) -> ContainerRequest<I>;
fn with_log_consumer(
self,
log_consumer: impl LogConsumer + 'static,
) -> ContainerRequest<I>;
}Expand description
Represents an extension for the Image trait.
Allows to override image defaults and container configuration.
Required Methods§
Sourcefn with_cmd(
self,
cmd: impl IntoIterator<Item = impl Into<String>>,
) -> ContainerRequest<I>
fn with_cmd( self, cmd: impl IntoIterator<Item = impl Into<String>>, ) -> ContainerRequest<I>
Returns a new ContainerRequest with the specified (overridden) CMD (Image::cmd).
§Examples
use testcontainers::{GenericImage, ImageExt};
let image = GenericImage::new("image", "tag");
let cmd = ["arg1", "arg2"];
let overridden_cmd = image.clone().with_cmd(cmd);
assert!(overridden_cmd.cmd().eq(cmd));
let another_container_req = image.with_cmd(cmd);
assert!(another_container_req.cmd().eq(overridden_cmd.cmd()));Sourcefn with_name(self, name: impl Into<String>) -> ContainerRequest<I>
fn with_name(self, name: impl Into<String>) -> ContainerRequest<I>
Overrides the fully qualified image name (consists of {domain}/{owner}/{image}).
Can be used to specify a custom registry or owner.
Sourcefn with_tag(self, tag: impl Into<String>) -> ContainerRequest<I>
fn with_tag(self, tag: impl Into<String>) -> ContainerRequest<I>
Overrides the image tag.
There is no guarantee that the specified tag for an image would result in a running container. Users of this API are advised to use this at their own risk.
Sourcefn with_container_name(self, name: impl Into<String>) -> ContainerRequest<I>
fn with_container_name(self, name: impl Into<String>) -> ContainerRequest<I>
Sets the container name.
Sourcefn with_network(self, network: impl Into<String>) -> ContainerRequest<I>
fn with_network(self, network: impl Into<String>) -> ContainerRequest<I>
Sets the network the container will be connected to.
Sourcefn with_label(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> ContainerRequest<I>
fn with_label( self, key: impl Into<String>, value: impl Into<String>, ) -> ContainerRequest<I>
Adds the specified label to the container.
Note: all keys in the org.testcontainers.* namespace should be regarded
as reserved by testcontainers internally, and should not be expected or relied
upon to be applied correctly if supplied as a value for key.
Sourcefn with_labels(
self,
labels: impl IntoIterator<Item = (impl Into<String>, impl Into<String>)>,
) -> ContainerRequest<I>
fn with_labels( self, labels: impl IntoIterator<Item = (impl Into<String>, impl Into<String>)>, ) -> ContainerRequest<I>
Adds the specified labels to the container.
Note: all keys in the org.testcontainers.* namespace should be regarded
as reserved by testcontainers internally, and should not be expected or relied
upon to be applied correctly if they are included in labels.
Sourcefn with_env_var(
self,
name: impl Into<String>,
value: impl Into<String>,
) -> ContainerRequest<I>
fn with_env_var( self, name: impl Into<String>, value: impl Into<String>, ) -> ContainerRequest<I>
Adds an environment variable to the container.
Sourcefn with_host(
self,
key: impl Into<String>,
value: impl Into<Host>,
) -> ContainerRequest<I>
fn with_host( self, key: impl Into<String>, value: impl Into<Host>, ) -> ContainerRequest<I>
Adds a host to the container.
Sourcefn with_mount(self, mount: impl Into<Mount>) -> ContainerRequest<I>
fn with_mount(self, mount: impl Into<Mount>) -> ContainerRequest<I>
Adds a mount to the container.
Sourcefn with_copy_to(
self,
target: impl Into<String>,
source: impl Into<CopyDataSource>,
) -> ContainerRequest<I>
fn with_copy_to( self, target: impl Into<String>, source: impl Into<CopyDataSource>, ) -> ContainerRequest<I>
Copies some source into the container as file
Sourcefn with_mapped_port(
self,
host_port: u16,
container_port: ContainerPort,
) -> ContainerRequest<I>
fn with_mapped_port( self, host_port: u16, container_port: ContainerPort, ) -> ContainerRequest<I>
Adds a port mapping to the container, mapping the host port to the container’s internal port.
§Examples
use testcontainers::{GenericImage, ImageExt};
use testcontainers::core::IntoContainerPort;
let image = GenericImage::new("image", "tag").with_mapped_port(8080, 80.tcp());Sourcefn with_ulimit(
self,
name: &str,
soft: i64,
hard: Option<i64>,
) -> ContainerRequest<I>
fn with_ulimit( self, name: &str, soft: i64, hard: Option<i64>, ) -> ContainerRequest<I>
Adds a resource ulimit to the container.
§Examples
use testcontainers::{GenericImage, ImageExt};
let image = GenericImage::new("image", "tag").with_ulimit("nofile", 65536, Some(65536));Sourcefn with_privileged(self, privileged: bool) -> ContainerRequest<I>
fn with_privileged(self, privileged: bool) -> ContainerRequest<I>
Sets the container to run in privileged mode.
Sourcefn with_cap_add(self, capability: impl Into<String>) -> ContainerRequest<I>
fn with_cap_add(self, capability: impl Into<String>) -> ContainerRequest<I>
Adds the capabilities to the container
Sourcefn with_cap_drop(self, capability: impl Into<String>) -> ContainerRequest<I>
fn with_cap_drop(self, capability: impl Into<String>) -> ContainerRequest<I>
Drops the capabilities from the container’s capabilities
Sourcefn with_cgroupns_mode(self, cgroupns_mode: CgroupnsMode) -> ContainerRequest<I>
fn with_cgroupns_mode(self, cgroupns_mode: CgroupnsMode) -> ContainerRequest<I>
cgroup namespace mode for the container. Possible values are:
CgroupnsMode::Private: the container runs in its own private cgroup namespaceCgroupnsMode::Host: use the host system’s cgroup namespace
If not specified, the daemon default is used, which can either be \"private\" or \"host\", depending on daemon version, kernel support and configuration.
Sourcefn with_userns_mode(self, userns_mode: &str) -> ContainerRequest<I>
fn with_userns_mode(self, userns_mode: &str) -> ContainerRequest<I>
Sets the usernamespace mode for the container when usernamespace remapping option is enabled.
Sourcefn with_shm_size(self, bytes: u64) -> ContainerRequest<I>
fn with_shm_size(self, bytes: u64) -> ContainerRequest<I>
Sets the shared memory size in bytes
Sourcefn with_startup_timeout(self, timeout: Duration) -> ContainerRequest<I>
fn with_startup_timeout(self, timeout: Duration) -> ContainerRequest<I>
Sets the startup timeout for the container. The default is 60 seconds.
Sourcefn with_working_dir(self, working_dir: impl Into<String>) -> ContainerRequest<I>
fn with_working_dir(self, working_dir: impl Into<String>) -> ContainerRequest<I>
Sets the working directory. The default is defined by the underlying image, which in turn may default to /.
Sourcefn with_log_consumer(
self,
log_consumer: impl LogConsumer + 'static,
) -> ContainerRequest<I>
fn with_log_consumer( self, log_consumer: impl LogConsumer + 'static, ) -> ContainerRequest<I>
Adds the log consumer to the container.
Allows to follow the container logs for the whole lifecycle of the container, starting from the creation.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
impl<RI, I> ImageExt<I> for RI
Implements the ImageExt trait for the every type that can be converted into a ContainerRequest.