Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions core/src/main/java/org/testcontainers/DockerClientFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ public TransportConfig getTransportConfig() {
return getOrInitializeStrategy().getTransportConfig();
}

/**
* Returns the path to the Docker socket, suitable for mapping into the container itself via a volume.
*
* In some special cases, this might not be the same path that this library uses to talk to Docker;
* for example, if Docker is running inside a VM, this path is the path to the Docker socket within
* the VM.
*/
@UnstableAPI
public String getRemoteDockerUnixSocketPath() {
String dockerSocketOverride = System.getenv("TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE");
Expand All @@ -164,6 +171,16 @@ public String getRemoteDockerUnixSocketPath() {
}

URI dockerHost = getTransportConfig().getDockerHost();

// Special case: it looks like we are running Colima on a Mac. Colima runs a VM. Inside
// the VM, you need to access Docker via /var/run/docker.sock; on the Mac itself, you
// need to access it via something like ~/.colima/default/docker.sock, which can be found
// via the current Docker context. To make this just work by default, if it looks like we're
// running Colima, return the path that works inside the VM.
if (dockerHost.getRawPath().contains("/.colima/")) {
return "/var/run/docker.sock";
}

String path = "unix".equals(dockerHost.getScheme()) ? dockerHost.getRawPath() : "/var/run/docker.sock";
return SystemUtils.IS_OS_WINDOWS ? "/" + path : path;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public EnvironmentAndSystemPropertyClientProviderStrategy() {
}

EnvironmentAndSystemPropertyClientProviderStrategy(DefaultDockerClientConfig.Builder configBuilder) {
boolean applicable = false;
String dockerConfigSource = TestcontainersConfiguration
.getInstance()
.getEnvVarOrProperty("dockerconfig.source", "auto");
Expand All @@ -55,6 +56,18 @@ public EnvironmentAndSystemPropertyClientProviderStrategy() {
}

dockerClientConfig = configBuilder.build();
// DefaultDockerClientConfig.Builder is often able to read a docker host from the current context file.
// If it does not find such a thing and there's also no explicit host setting, it will set the host to the default
// Unix or Windows socket location. So if we find something other than those defaults, we'll use it; otherwise,
// we'll let other strategies kick in (including UnixSocketClientProviderStrategy and NpipeSocketClientProviderStrategy
// themselves).
applicable =
applicable ||
(
!dockerClientConfig.getDockerHost().equals(UnixSocketClientProviderStrategy.SOCKET_LOCATION) &&
!dockerClientConfig.getDockerHost().equals(NpipeSocketClientProviderStrategy.SOCKET_LOCATION)
);
this.applicable = applicable;
}

private Optional<String> getSetting(final String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public final class NpipeSocketClientProviderStrategy extends DockerClientProvide

protected static final String DOCKER_SOCK_PATH = "//./pipe/docker_engine";

private static final String SOCKET_LOCATION = "npipe://" + DOCKER_SOCK_PATH;
protected static final String SOCKET_LOCATION = "npipe://" + DOCKER_SOCK_PATH;

public static final int PRIORITY = EnvironmentAndSystemPropertyClientProviderStrategy.PRIORITY - 20;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public final class UnixSocketClientProviderStrategy extends DockerClientProvider

protected static final String DOCKER_SOCK_PATH = "/var/run/docker.sock";

private static final String SOCKET_LOCATION = "unix://" + DOCKER_SOCK_PATH;
protected static final String SOCKET_LOCATION = "unix://" + DOCKER_SOCK_PATH;

private static final int SOCKET_FILE_MODE_MASK = 0xc000;

Expand Down
67 changes: 29 additions & 38 deletions docs/supported_docker_environment/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,46 @@

## Overview

Testcontainers requires a Docker-API compatible container runtime.
During development, Testcontainers is actively tested against recent versions of Docker on Linux, as well as against Docker Desktop on Mac and Windows.
Testcontainers requires a Docker-API compatible container runtime.
During development, Testcontainers is actively tested against recent versions of Docker on Linux, as well as against Docker Desktop on Mac and Windows.
These Docker environments are automatically detected and used by Testcontainers without any additional configuration being necessary.

It is possible to configure Testcontainers to work for other Docker setups, such as a remote Docker host or Docker alternatives.
However, these are not actively tested in the main development workflow, so not all Testcontainers features might be available and additional manual configuration might be necessary.
If you have further questions about configuration details for your setup or whether it supports running Testcontainers-based tests,
It is possible to configure Testcontainers to work for other Docker setups, such as a remote Docker host or Docker alternatives.
However, these are not actively tested in the main development workflow, so not all Testcontainers features might be available and additional manual configuration might be necessary.
If you have further questions about configuration details for your setup or whether it supports running Testcontainers-based tests,
please contact the Testcontainers team and other users from the Testcontainers community on [Slack](https://slack.testcontainers.org/).

| Host Operating System / Environment | Minimum recommended docker versions | Known issues / tips |
|-------------------------------------|-----------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Linux - general | Docker v17.09 | After docker installation, follow [post-installation steps](https://docs.docker.com/engine/install/linux-postinstall/). |
| Linux - CircleCI (LXC driver) | Docker v17.09 | The `exec` feature is not compatible with CircleCI. See CircleCI configuration [example](./continuous_integration/circle_ci.md) |
| Linux - within a Docker container | Docker v17.09 | See [Running inside Docker](continuous_integration/dind_patterns.md) for Docker-in-Docker and Docker wormhole patterns |
| Mac OS X - Docker Toolbox | Docker Machine v0.8.0 | |
| Mac OS X - Docker for Mac | v17.09 | Starting 4.13, run `sudo ln -s $HOME/.docker/run/docker.sock /var/run/docker.sock`<br>Support is best-efforts at present<br>`getTestHostIpAddress()` is [not currently supported](https://github.com/testcontainers/testcontainers-java/issues/166) due to limitations in Docker for Mac. |
| Windows - Docker Toolbox | | *Support is limited at present and this is not currently tested on a regular basis*. |
| Windows - Docker for Windows | | *Support is best-efforts at present.* Only Linux Containers (LCOW) are supported at the moment. See [Windows Support](windows.md) |
| Windows - Windows Subsystem for Linux (WSL) | Docker v17.09 | *Support is best-efforts at present.* Only Linux Containers (LCOW) are supported at the moment. See [Windows Support](windows.md). |

## Using Colima?

In order to run testcontainers against [colima](https://github.com/abiosoft/colima) the env vars bellow should be set

```bash
export TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=/var/run/docker.sock
export DOCKER_HOST="unix://${HOME}/.colima/docker.sock"
```
| Host Operating System / Environment | Minimum recommended docker versions | Known issues / tips |
| ------------------------------------------- | ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Linux - general | Docker v17.09 | After docker installation, follow [post-installation steps](https://docs.docker.com/engine/install/linux-postinstall/). |
| Linux - CircleCI (LXC driver) | Docker v17.09 | The `exec` feature is not compatible with CircleCI. See CircleCI configuration [example](./continuous_integration/circle_ci.md) |
| Linux - within a Docker container | Docker v17.09 | See [Running inside Docker](continuous_integration/dind_patterns.md) for Docker-in-Docker and Docker wormhole patterns |
| Mac OS X - Docker Toolbox | Docker Machine v0.8.0 | |
| Mac OS X - Docker for Mac | v17.09 | Starting 4.13, run `sudo ln -s $HOME/.docker/run/docker.sock /var/run/docker.sock`<br>Support is best-efforts at present<br>`getTestHostIpAddress()` is [not currently supported](https://github.com/testcontainers/testcontainers-java/issues/166) due to limitations in Docker for Mac. |
| Windows - Docker Toolbox | | _Support is limited at present and this is not currently tested on a regular basis_. |
| Windows - Docker for Windows | | _Support is best-efforts at present._ Only Linux Containers (LCOW) are supported at the moment. See [Windows Support](windows.md) |
| Windows - Windows Subsystem for Linux (WSL) | Docker v17.09 | _Support is best-efforts at present._ Only Linux Containers (LCOW) are supported at the moment. See [Windows Support](windows.md). |

## Docker environment discovery

Testcontainers will try to connect to a Docker daemon using the following strategies in order:

* Environment variables:
* `DOCKER_HOST`
* `DOCKER_TLS_VERIFY`
* `DOCKER_CERT_PATH`
* Defaults:
* `DOCKER_HOST=https://localhost:2376`
* `DOCKER_TLS_VERIFY=1`
* `DOCKER_CERT_PATH=~/.docker`
* 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.
* 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.
- Environment variables:
- `DOCKER_HOST`
- `DOCKER_TLS_VERIFY`
- `DOCKER_CERT_PATH`
- Defaults:
- `DOCKER_HOST=https://localhost:2376`
- `DOCKER_TLS_VERIFY=1`
- `DOCKER_CERT_PATH=~/.docker`
- 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.
- 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.

## Docker registry authentication

Testcontainers will try to authenticate to registries with supplied config using the following strategies in order:

* Environment variables:
* `DOCKER_AUTH_CONFIG`
* Docker config
* At location specified in `DOCKER_CONFIG` or at `{HOME}/.docker/config.json`
- Environment variables:
- `DOCKER_AUTH_CONFIG`
- Docker config
- At location specified in `DOCKER_CONFIG` or at `{HOME}/.docker/config.json`