testcontainers-java
testcontainers-java copied to clipboard
Fix UnixSocketClientProviderStrategy ignoring DOCKER_HOST env var fixes #11254
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
getTransportConfiginUnixSocketClientProviderStrategy.javato check for theDOCKER_HOSTenvironment variable before defaulting to the hardcoded path. - Refactor: Removed the
finalmodifier fromUnixSocketClientProviderStrategyand extracted environment variable access to aprotectedmethod (getDockerHostEnv). This was necessary to make the class testable via partial mocking. - Test: Added a new unit test
shouldRespectDockerHostEnvVarinUnixSocketClientProviderStrategyTestthat 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