diff --git a/testcontainers/core/docker_client.py b/testcontainers/core/docker_client.py index e10537aa..0f27ca78 100644 --- a/testcontainers/core/docker_client.py +++ b/testcontainers/core/docker_client.py @@ -14,6 +14,7 @@ import urllib import docker from docker.models.containers import Container +from docker.transport import UnixHTTPAdapter from testcontainers.core.utils import inside_container from testcontainers.core.utils import default_gateway_ip @@ -72,11 +73,14 @@ def host(self): except ValueError: return None + adapter = self.client.api.get_adapter(self.client.api.base_url) + is_ipc = isinstance(adapter, UnixHTTPAdapter) + is_ipc |= hasattr(adapter, "socket_path") or hasattr(adapter, "npipe_path") + is_ipc |= 'unix' in url.scheme or 'npipe' in url.scheme + if is_ipc and inside_container(): + ip_address = default_gateway_ip() + if ip_address: + return ip_address if 'http' in url.scheme or 'tcp' in url.scheme: return url.hostname - if 'unix' in url.scheme or 'npipe' in url.scheme: - if inside_container(): - ip_address = default_gateway_ip() - if ip_address: - return ip_address return "localhost"