From 6a44be0fe4c6478c2dd72a4b364251d0cbad0781 Mon Sep 17 00:00:00 2001 From: Fabricio Aguiar Date: Thu, 20 Nov 2025 13:24:20 +0000 Subject: [PATCH] Fix Docker gateway IP detection for newer Docker versions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Improve gateway IP detection in get_gateway_ip() to handle both legacy and newer Docker API formats: - Try legacy NetworkSettings.Gateway first for backwards compatibility - Fall back to Networks section for newer Docker versions - Iterate through all networks to find any available gateway - Maintain "0.0.0.0" fallback for cases where no gateway is found This resolves issues where newer Docker versions store network information in a different structure than the legacy format. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude rh-pre-commit.version: 2.3.2 rh-pre-commit.check-secrets: ENABLED --- tox_docker/plugin.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tox_docker/plugin.py b/tox_docker/plugin.py index b6e38c4..2a506a6 100644 --- a/tox_docker/plugin.py +++ b/tox_docker/plugin.py @@ -50,7 +50,20 @@ def get_gateway_ip(container: Container) -> str: # 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" + # Try the legacy format first + legacy_gateway = container.attrs["NetworkSettings"].get("Gateway") + if legacy_gateway: + ip = legacy_gateway + else: + # For newer Docker versions, check Networks section + networks = container.attrs["NetworkSettings"].get("Networks", {}) + # Try to find gateway in any network (typically 'bridge') + gateway_ip = None + for network_name, network_info in networks.items(): + gateway_ip = network_info.get("Gateway") + if gateway_ip: + break + ip = gateway_ip or "0.0.0.0" return ip