testcontainers-go
testcontainers-go copied to clipboard
fix: preserve unix socket schema in testcontainersHostFromProperties
What does this PR do?
This PR fixes an issue where UNIX domain socket URLs configured in the tc.host property in ~/.testcontainers.properties would have their schema stripped, causing Docker client initialization to fail.
Changes made:
- Modified
testcontainersHostFromPropertiesfunction to preserve the original URL with schema after validation - Added test coverage for UNIX socket schema preservation in the properties file
- Ensured backward compatibility for TCP hosts and other existing functionality
Technical details:
The function now validates the URL format using parseURL() but returns the original URL instead of the parsed result, ensuring the Docker client receives the full URL with schema (e.g., unix:///var/run/docker.sock instead of just /var/run/docker.sock).
Initially, I considered modifying parseURL() to preserve the schema for UNIX sockets. However, this function is also used by dockerHostFromContext which expects only the path portion (without schema) for internal operations.
To avoid breaking existing functionality, I chose a more targeted approach: update testcontainersHostFromProperties now.
Why is it important?
When users configure UNIX domain sockets in ~/.testcontainers.properties using tc.host=unix:///var/run/docker.sock, the application would panic with:
panic: check host "/var/run/docker.sock": new client: unable to parse docker host `/var/run/docker.sock`
This occurs because:
testcontainersHostFromPropertiescallsparseURL()which strips theunix://schema- The stripped path is passed to
dockerHostCheck - Docker client's ParseHostURL expects
protocol://addressformat, but receives only the path - Client initialization fails with a parsing error
This fix ensures UNIX socket configurations in ~/.testcontainers.properties work correctly while maintaining compatibility with existing TCP host configurations.
Related issues
If an issue should be created first, I'm happy to create one before merging this PR