Custom Configuration
Testcontainers supports various configurations to set up your test environment. It automatically discovers the Docker environment and applies the configuration. You can set or override the default values either with the Testcontainers properties file (~/.testcontainers.properties
) or with environment variables. The following configurations are available:
Properties File | Environment Variable | Description | Default |
---|---|---|---|
docker.config |
DOCKER_CONFIG |
The directory path that contains the Docker configuration (config.json ) file. |
~/.docker/ |
docker.host |
DOCKER_HOST |
The Docker daemon socket to connect to. | - |
docker.auth.config |
DOCKER_AUTH_CONFIG |
The Docker configuration file content (GitLab: Use statically-defined credentials). | - |
docker.cert.path |
DOCKER_CERT_PATH |
The directory path that contains the client certificate ({ca,cert,key}.pem ) files. |
~/.docker/ |
docker.tls |
DOCKER_TLS |
Enables TLS. | false |
docker.tls.verify |
DOCKER_TLS_VERIFY |
Enables TLS verify. | false |
host.override |
TESTCONTAINERS_HOST_OVERRIDE |
The host that exposes Docker's ports. | - |
docker.socket.override |
TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE |
The file path to the Docker daemon socket that is used by Ryuk (resource reaper). | /var/run/docker.sock |
ryuk.disabled |
TESTCONTAINERS_RYUK_DISABLED |
Disables Ryuk (resource reaper). | false |
ryuk.container.privileged |
TESTCONTAINERS_RYUK_CONTAINER_PRIVILEGED |
Runs Ryuk (resource reaper) in privileged mode. | false |
ryuk.container.image |
TESTCONTAINERS_RYUK_CONTAINER_IMAGE |
The Ryuk (resource reaper) Docker image. | testcontainers/ryuk:0.5.1 |
hub.image.name.prefix |
TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX |
The name to use for substituting the Docker Hub registry part of the image name. | - |
wait.strategy.retries |
TESTCONTAINERS_WAIT_STRATEGY_RETRIES |
The wait strategy retry count. | infinite |
wait.strategy.interval |
TESTCONTAINERS_WAIT_STRATEGY_INTERVAL |
The wait strategy interval1. | 00:00:01 |
wait.strategy.timeout |
TESTCONTAINERS_WAIT_STRATEGY_TIMEOUT |
The wait strategy timeout1. | 01:00:00 |
1) The value represent the string representation of a TimeSpan, for example, 00:00:01
for 1 second.
Configure remote container runtime
To configure a remote container runtime, Testcontainers provides support for Docker's environment variables in addition to the properties file. During initialization, Testcontainers' auto-discovery feature detect and apply custom configurations including container runtimes. If you are running Docker on a remote host, you can configure it using either of the following methods:
1 |
|
1 |
|
Enable logging
In .NET logging usually goes through the test framework. Testcontainers is not aware of the project's test framework and may not forward log messages to the appropriate output stream. The default implementation forwards log messages to the Console
(respectively stdout
and stderr
). The output should at least pop up in the IDE running tests in the Debug
configuration. To override the default implementation, use the builder's WithLogger(ILogger)
method and provide an ILogger
instance to replace the default console logger.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
Tip
These log messages are from the Testcontainers library and contain information about the test resources. They do not include log messages from the containers. To get the container log messages, see: Getting log messages.
To enable debug log messages in the default implementation, set the property ConsoleLogger.Instance.DebugLogLevelEnabled
to true
. This will forward messages related to building or pulling Docker images to the output stream.