testcontainers / testcontainers/testcontainers-java
[Bug]: DockerDesktopClientProviderStrategy is always applicable
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 8.7k
- Forks
- 1.9k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 9
Description
Module
Core
Testcontainers version
2.0.5
Using the latest Testcontainers version?
Yes
Host OS
macOS
Host Arch
ARM
Docker version
29.5.3
What happened?
DockerDesktopClientProviderStrategy is always applicable even when Docker Desktop is not installed at all. It happens because the socketPath field is annotated with @Getter(lazy = true) and so its actual type is AtomicReference, but the isApplicable() method checks nullability as this.socketPath != null.
@Getter(lazy = true)
@Nullable
private final Path socketPath = resolveSocketPath();
@Override
protected boolean isApplicable() {
return (SystemUtils.IS_OS_LINUX || SystemUtils.IS_OS_MAC) && this.socketPath != null;
}
Finally, the getTransportConfig() method fails with NPE as getSocketPath() returns null.
@Override
public TransportConfig getTransportConfig() throws InvalidConfigurationException {
return TransportConfig.builder().dockerHost(URI.create("unix://" + getSocketPath().toString())).build();
}
Relevant log output
[Test worker] ERROR o.t.d.DockerClientProviderStrategy - Could not find a valid Docker environment. Please check configuration. Attempted configurations were:
UnixSocketClientProviderStrategy: failed with exception InvalidConfigurationException (Could not find unix domain socket). Root cause NoSuchFileException (/var/run/docker.sock)
DockerDesktopClientProviderStrategy: failed with exception NullPointerException (Cannot invoke "java.nio.file.Path.toString()" because the return value of "org.testcontainers.dockerclient.DockerDesktopClientProviderStrategy.getSocketPath()" is null)
Additional Information
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Inspect DockerDesktopClientProviderStrategy, focusing on socketPath, isApplicable(), and getTransportConfig(). Start by reproducing the strategy selection on macOS without Docker Desktop, then review nearby tests or the strategy test suite. Done means the strategy is not selected when its socket is unavailable and no NullPointerException occurs while configurations are attempted.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, java
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 74/100