Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions tox_docker/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,23 @@ class HealthCheckFailed(Exception):
def get_gateway_ip(container: Container) -> str:
gateway = os.getenv("TOX_DOCKER_GATEWAY")
if gateway:
ip = socket.gethostbyname(gateway)
elif sys.platform == "darwin":
return socket.gethostbyname(gateway)
if sys.platform == "darwin":
# https://docs.docker.com/docker-for-mac/networking/#use-cases-and-workarounds:
# there is no bridge network available in Docker for Mac, and exposed ports are
# made available on localhost (but 0.0.0.0 works just as well)
ip = "0.0.0.0"
else:
ip = container.attrs["NetworkSettings"]["Gateway"] or "0.0.0.0"
return ip
return "0.0.0.0"
network_settings = container.attrs["NetworkSettings"]
for network in network_settings.get("Networks", {}).values():
# preferred interface as of v1.21 API (docker 1.9.0, 2015-11-03)
# note behavior may not be correct if there are multiple networks.
# a more robust approach may be to prefer specific networks, i.e. "bridge"
if ip := network.get("Gateway"):
return ip
if ip := network_settings.get("Gateway"):
# deprecated interface, removed in v1.52 API (docker 29.0.0, 2025-11-10)
return ip
return "0.0.0.0"


def escape_env_var(varname: str) -> str:
Expand Down