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

[#50] Consider Docker host IP during port mapping resolution

Open rvem opened this issue 10 months ago • 8 comments

In some cases, 'localhost' might be resolved to IPv6 '::1', while 'containerPort' will grab IPv4 host IP port mapping by default, when Docker maps different ports for host's IPv4 and IPv6 addresses, this might cause timeout errors.

To solve this issue, the Docker host is resolved from 'localhost' at container creation time, host IP protocol version is later used to deduce the corresponding port in 'containerPort' function.

Additionally, helper 'containerAddress', as well as 'TraceOpenSocket' and 'TraceHttpCall' now operate 'IP' addresses instead of plain 'Text' domains. This should be safe since we only actually consider domains within some Docker network or 'localhost' at the moment.

My solution is quite hacky since I was a bit afraid to break backward compatibility, would be happy to hear your feedback

Somewhat resolves #50.

rvem avatar Apr 18 '24 11:04 rvem