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
+23-4
Original file line number
Diff line number
Diff line change
@@ -9,14 +9,28 @@
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>
18
19
* </ol>
19
-
*
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>
32
+
* </ol>
33
+
*
20
34
* @deprecated this class is used by the SPI and should not be used directly
21
35
*/
22
36
@Deprecated
@@ -43,9 +57,14 @@ public EnvironmentAndSystemPropertyClientProviderStrategy() {
Copy file name to clipboardExpand all lines: docs/supported_docker_environment/index.md
+16-20
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ 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,
@@ -21,7 +21,14 @@ please contact the Testcontainers team and other users from the Testcontainers c
21
21
22
22
## Colima
23
23
24
-
In order to run testcontainers against [colima](https://github.com/abiosoft/colima) the env vars below should be set
24
+
In order to run testcontainers against [colima](https://github.com/abiosoft/colima) the standard configuration should be automatically detected. Starting colima should be enough.
25
+
26
+
```bash
27
+
colima start --network-address
28
+
docker context use colima
29
+
```
30
+
31
+
For more complex scenarios you should configure the following environment variables:
In order to run testcontainers against [Rancher Desktop](https://rancherdesktop.io/) the env vars below should be set.
65
-
66
-
If you're running Rancher Desktop as an administrator in a MacOS (M1) machine:
67
-
68
-
Using QEMU emulation
69
-
70
-
```bash
71
-
export TESTCONTAINERS_HOST_OVERRIDE=$(rdctl shell ip a show rd0 | awk '/inet / {sub("/.*",""); print $2}')
72
-
```
73
-
74
-
Using VZ emulation
75
-
76
-
```bash
77
-
export TESTCONTAINERS_HOST_OVERRIDE=$(rdctl shell ip a show vznat | awk '/inet / {sub("/.*",""); print $2}')
78
-
```
79
-
80
-
If you're not running Rancher Desktop as an administrator in a MacOS (M1) machine:
71
+
In order to run testcontainers against [Rancher Desktop](https://rancherdesktop.io/) the standard configuration should be automatically detected. Starting colima should be enough.
81
72
82
-
Using VZ emulation
73
+
For more complex scenarios you should configure the following environment variables:
83
74
84
75
```bash
85
76
export DOCKER_HOST=unix://$HOME/.rd/docker.sock
@@ -95,10 +86,15 @@ Testcontainers will try to connect to a Docker daemon using the following strate
95
86
* `DOCKER_HOST`
96
87
* `DOCKER_TLS_VERIFY`
97
88
* `DOCKER_CERT_PATH`
89
+
* `DOCKER_CONTEXT`
90
+
* `DOCKER_CONFIG`
98
91
* Defaults:
99
92
* `DOCKER_HOST=https://localhost:2376`
100
93
* `DOCKER_TLS_VERIFY=1`
101
94
* `DOCKER_CERT_PATH=~/.docker`
95
+
* `DOCKER_CONTEXT=$(docker context show)`
96
+
* `DOCKER_CONFIG=~/.docker`
97
+
* If the current docker context provides a working Docker environment, it will be preferred to further installation detection.
102
98
* 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
99
* 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.
0 commit comments