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
Improve support for alternative container runtimes
In several cases, alternative container runtimes offers a docker
compatible API and populates the docker context accordingly.
However, in the current implementation of testcontainers, the context is
often ignored as the `EnvironmentAndSystemPropertyClientProviderStrategy` only considers
the `DOCKER_HOST` override either through testcontainers property or the
environment variables.
Improve the support of multiple container runtimes by honoring the
current docker context.
In addition, improve the detection of whether the Docker engine runs
in a virtual machine without root access for the current user, so it
removes the need to configure `TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE` in
standard cases.
This change has been tested with:
- colima
- rancher desktop (in non-privileged mode)
- docker desktop
- orbstack
Copy file name to clipboardExpand all lines: core/src/main/java/org/testcontainers/dockerclient/EnvironmentAndSystemPropertyClientProviderStrategy.java
+22-3
Original file line number
Diff line number
Diff line change
@@ -9,12 +9,26 @@
9
9
10
10
/**
11
11
* Use environment variables and system properties (as supported by the underlying DockerClient DefaultConfigBuilder)
12
-
* to try and locate a docker environment.
12
+
* to try and locate a docker environment based on the currently active configuration.
13
13
* <p>
14
-
* Resolution order is:
14
+
* Docker Host resolution order is:
15
15
* <ol>
16
16
* <li>DOCKER_HOST env var</li>
17
17
* <li>docker.host in ~/.testcontainers.properties</li>
18
+
* <li>docker host pointed by the Docker context</li>
19
+
* </ol>
20
+
* <p>
21
+
* Docker context resolution order is
22
+
* <ol>
23
+
* <li>DOCKER_CONTEXT env var</li>
24
+
* <li>docker.context in ~/.testcontainers.properties</li>
25
+
* <li>current docker context pointed by the Docker config</li>
26
+
* </ol>
27
+
* <p>
28
+
* Docker config resolution order is
29
+
* <ol>
30
+
* <li>DOCKER_CONFIG env var</li>
31
+
* <li>$HOME/.docker</li>
18
32
* </ol>
19
33
*
20
34
* @deprecated this class is used by the SPI and should not be used directly
@@ -43,9 +57,14 @@ public EnvironmentAndSystemPropertyClientProviderStrategy() {
Copy file name to clipboardExpand all lines: docs/supported_docker_environment/index.md
+25-52
Original file line number
Diff line number
Diff line change
@@ -11,24 +11,40 @@ These Docker environments are automatically detected and used by Testcontainers
11
11
12
12
It is possible to configure Testcontainers to work with alternative container runtimes.
13
13
Making use of the free [Testcontainers Desktop](https://testcontainers.com/desktop/) app will take care of most of the manual configuration.
14
-
When using those alternatives without Testcontainers Desktop,
14
+
Although Testcontainers has a detection for most of the cases, when using those alternatives without Testcontainers Desktop,
15
15
sometimes some manual configuration might be necessary
16
16
(see further down for specific runtimes, or [Customizing Docker host detection](/features/configuration/#customizing-docker-host-detection) for general configuration mechanisms).
17
17
Alternative container runtimes are not actively tested in the main development workflow,
18
18
so not all Testcontainers features might be available.
19
19
If you have further questions about configuration details for your setup or whether it supports running Testcontainers-based tests,
20
20
please contact the Testcontainers team and other users from the Testcontainers community on [Slack](https://slack.testcontainers.org/).
21
21
22
-
## Colima
22
+
## Docker environment discovery
23
23
24
-
In order to run testcontainers against [colima](https://github.com/abiosoft/colima) the env vars below should be set
24
+
Testcontainers will try to connect to a Docker daemon using the following strategies in order:
25
+
26
+
* Environment variables:
27
+
* `DOCKER_HOST`
28
+
* `DOCKER_TLS_VERIFY`
29
+
* `DOCKER_CERT_PATH`
30
+
* `DOCKER_CONTEXT`
31
+
* `DOCKER_CONFIG`
32
+
* Defaults:
33
+
* `DOCKER_HOST=https://localhost:2376`
34
+
* `DOCKER_TLS_VERIFY=1`
35
+
* `DOCKER_CERT_PATH=~/.docker`
36
+
* `DOCKER_CONTEXT=$(docker context show)`
37
+
* `DOCKER_CONFIG=~/.docker`
38
+
* If the current docker context provides a working Docker environment, it will be preferred to further installation detection.
39
+
* If Docker Machine is installed, the docker machine environment for the *first* machine found. Docker Machine needs to be on the PATH for this to succeed.
40
+
* If you're going to run your tests inside a container, please read [Patterns for running tests inside a docker container](continuous_integration/dind_patterns.md) first.
41
+
42
+
Although this detection works in the majority of docker installations, for more complex installations, you may need to [customize the docker host detection](/features/configuration/#customizing-docker-host-detection).
43
+
44
+
When the Docker socket either differs from a unix socket or is running inside the user home directory, Testcontainers will consider the Docker host as remote
45
+
and the docker host mounted by containers like Ryuk will default to `/var/run/docker.sock`.
46
+
If you have a different configuration, you will need to use the `TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE` environment variable.
export TESTCONTAINERS_HOST_OVERRIDE=$(rdctl shell ip a show vznat | awk '/inet / {sub("/.*",""); print $2}')
88
-
```
89
-
90
-
## Docker environment discovery
91
-
92
-
Testcontainers will try to connect to a Docker daemon using the following strategies in order:
93
-
94
-
* Environment variables:
95
-
* `DOCKER_HOST`
96
-
* `DOCKER_TLS_VERIFY`
97
-
* `DOCKER_CERT_PATH`
98
-
* Defaults:
99
-
* `DOCKER_HOST=https://localhost:2376`
100
-
* `DOCKER_TLS_VERIFY=1`
101
-
* `DOCKER_CERT_PATH=~/.docker`
102
-
* If Docker Machine is installed, the docker machine environment for the *first* machine found. Docker Machine needs to be on the PATH for this to succeed.
103
-
* If you're going to run your tests inside a container, please read [Patterns for running tests inside a docker container](continuous_integration/dind_patterns.md) first.
104
-
105
78
## Docker registry authentication
106
79
107
80
Testcontainers will try to authenticate to registries with supplied config using the following strategies in order:
0 commit comments