To add a custom label to the container, use withLabel
:
Adding a single label inside_block:single_label
Additionally, multiple labels may be applied together from a map:
Adding multiple labels inside_block:multiple_labels
By default, the container image is retrieved from the local Docker images cache. This works well when running against a specific version, but for images with a static tag (i.e. 'latest') this may lead to a newer version not being pulled.
It is possible to specify an Image Pull Policy to determine at runtime whether an image should be pulled or not:
Setting image pull policy inside_block:built_in_image_pull_policy
... or providing a function:
Custom image pull policy inside_block:custom_image_pull_policy
It is possible to use the docker-java
API directly to customize containers before creation. This is useful if there is a need to use advanced Docker features that are not exposed by the Testcontainers API. Any customizations you make using withCreateContainerCmdModifier
will be applied on top of the container definition that Testcontainers creates, but before it is created.
For example, this can be used to change the container hostname:
Using modifier to change hostname inside_block:hostname
... or modify container memory (see this if it does not appear to work):
Using modifier to change memory limits inside_block:memory
!!! note
It is recommended to use this sparingly, and follow changes to the docker-java
API if you choose to use this.
It is typically quite stable, though.
For what is possible, consult the docker-java CreateContainerCmd
source code.