testcontainers-java icon indicating copy to clipboard operation
testcontainers-java copied to clipboard

Fix UnixSocketClientProviderStrategy ignoring DOCKER_HOST env var fixes #11254

Open WieczorekAdrian opened this issue 1 week ago • 0 comments

Context

In the current implementation (v2.x), UnixSocketClientProviderStrategy hardcodes the socket path to /var/run/docker.sock. It completely ignores the DOCKER_HOST environment variable.

This is a regression that prevents users (especially those using Podman or rootless Docker) from running tests if other strategies fail and the system falls back to this strategy.

Changes

  • Fix: Updated getTransportConfig in UnixSocketClientProviderStrategy.java to check for the DOCKER_HOST environment variable before defaulting to the hardcoded path.
  • Refactor: Removed the final modifier from UnixSocketClientProviderStrategy and extracted environment variable access to a protected method (getDockerHostEnv). This was necessary to make the class testable via partial mocking.
  • Test: Added a new unit test shouldRespectDockerHostEnvVar in UnixSocketClientProviderStrategyTest that verifies the fix by simulating a custom socket path.

Verification

I verified the fix locally using the added unit test, which fails without the fix and passes with it. I also ran spotlessApply to ensure code style compliance.

Fixes #11254

WieczorekAdrian avatar Dec 01 '25 17:12 WieczorekAdrian