You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/custom_configuration/index.md
+22Lines changed: 22 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -61,6 +61,28 @@ Setting the context to `tcc` in this example will use the Docker host running at
61
61
docker.context=tcc
62
62
```
63
63
64
+
## Substitute image names
65
+
66
+
Testcontainers supports substituting an image name with an alternative on the fly, for example to pull from a private registry mirror instead of Docker Hub. This is useful if you have complex rules that a simple prefix cannot express, such as a non-deterministic name mapping, rules depending on the developer or environment, or auditing and restricting the images used in a build.
67
+
68
+
Set `TestcontainersSettings.ImageNameSubstitution` to a function that receives the original `IImage` and returns the image to use instead. Return the original image (or `null`) to leave it unchanged.
69
+
70
+
Configure the substitution once before any test resources are created. A static class with a [`[ModuleInitializer]`](https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.moduleinitializerattribute) method runs automatically before the first type in the test assembly is used:
The substitution runs first, then the Docker Hub image name prefix (`TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX`) is applied to the substituted image. As with any image, the prefix is only added when the image does not already specify a registry, so a substitution that sets a registry (such as the examples above) takes precedence over the prefix.
85
+
64
86
## Automatically modify Docker Hub image names
65
87
66
88
Testcontainers can automatically add a registry prefix to Docker Hub image names used in your tests. This is handy if you use a private registry that mirrors Docker Hub images with predictable naming.
0 commit comments