Skip to content

Fix Docker gateway IP detection for newer Docker versions#196

Open
fao89 wants to merge 1 commit intotox-dev:masterfrom
fao89:fix/docker-gateway-compatibility
Open

Fix Docker gateway IP detection for newer Docker versions#196
fao89 wants to merge 1 commit intotox-dev:masterfrom
fao89:fix/docker-gateway-compatibility

Conversation

@fao89
Copy link

@fao89 fao89 commented Nov 20, 2025

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

Co-Authored-By: Claude noreply@anthropic.com

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 <noreply@anthropic.com>

rh-pre-commit.version: 2.3.2
rh-pre-commit.check-secrets: ENABLED
@jonathangreen
Copy link
Contributor

@dcrosta Any chance of this getting reviewed and merged? Happy to help in any way I can.

I have a project that uses tox-docker and I started seeing random CI failures in GitHub Actions today.

GitHub Actions runners are currently rolling out Docker 29 (started Feb 9, 2026 — see actions/runner-images#13474), which removed the deprecated top-level NetworkSettings.Gateway key from the container inspect API.

This causes tox-docker to crash with:

  File "tox_docker/plugin.py", line 53, in get_gateway_ip
      ip = container.attrs["NetworkSettings"]["Gateway"] or "0.0.0.0"
  KeyError: 'Gateway'

During the rollout, this manifests as flaky failures since some runners have Docker 28 and some have Docker 29. Once the rollout completes, it will be a 100% failure rate for anyone using tox-docker on GitHub Actions.

The TOX_DOCKER_GATEWAY env var works as a workaround (see: ThePalaceProject/library-registry#862), but it would be great to get this PR reviewed and a new release out so the workaround isn't needed.

jonathangreen added a commit to ThePalaceProject/virtual-library-card that referenced this pull request Feb 12, 2026
## Description

Added `TOX_DOCKER_GATEWAY` environment variable to the test workflow to
work around a `KeyError: 'Gateway'` failure in tox-docker when running
on Docker 29+.

Docker 29 [removed the deprecated top-level `NetworkSettings.Gateway`
key](https://docs.docker.com/engine/release-notes/29/) from the
container inspect API. tox-docker 5.0.0 relies on this key and crashes
with a `KeyError`. Setting `TOX_DOCKER_GATEWAY=0.0.0.0` bypasses the
broken lookup entirely.

This became flaky starting Feb 12 as the [Docker 29
rollout](actions/runner-images#13474) to
GitHub Actions runners progresses. Once complete, tests will fail 100%
of the time without this fix.

This workaround can be removed once [tox-docker merges the
fix](tox-dev/tox-docker#196).

Mirrors the fix applied in
[circulation#3045](ThePalaceProject/circulation#3045)
and
[library-registry#862](ThePalaceProject/library-registry#862).

## Motivation and Context

CI test runs are failing intermittently with:
```
tox_docker/plugin.py, line 53, in get_gateway_ip
    ip = container.attrs["NetworkSettings"]["Gateway"] or "0.0.0.0"
KeyError: 'Gateway'
```

## How Has This Been Tested?

- CI will validate that tests pass with the workaround on Docker 29+
runners

## Checklist

- [x] I have updated the documentation accordingly.
- [x] All new and existing tests passed.
jonathangreen added a commit to ThePalaceProject/circulation that referenced this pull request Feb 12, 2026
## Description

Added `TOX_DOCKER_GATEWAY` environment variable to the test workflow to
work around a `KeyError: 'Gateway'` failure in tox-docker when running
on Docker 29+.

Docker 29 [removed the deprecated top-level `NetworkSettings.Gateway`
key](https://docs.docker.com/engine/release-notes/29/) from the
container inspect API. tox-docker 5.0.0 relies on this key and crashes
with a `KeyError`. Setting `TOX_DOCKER_GATEWAY=0.0.0.0` bypasses the
broken lookup entirely.

This became flaky starting Feb 12 as the [Docker 29
rollout](actions/runner-images#13474) to
GitHub Actions runners progresses. Once complete, tests will fail 100%
of the time without this fix.

This workaround can be removed once [tox-docker merges the
fix](tox-dev/tox-docker#196).

Mirrors the fix applied in
[library-registry#862](ThePalaceProject/library-registry#862).

## Motivation and Context

CI test runs are failing intermittently with:
```
tox_docker/plugin.py, line 53, in get_gateway_ip
    ip = container.attrs["NetworkSettings"]["Gateway"] or "0.0.0.0"
KeyError: 'Gateway'
```

## How Has This Been Tested?

- CI will validate that tests pass with the workaround on Docker 29+
runners

## Checklist

- [x] I have updated the documentation accordingly.
- [x] All new and existing tests passed.
jonathangreen added a commit to ThePalaceProject/library-registry that referenced this pull request Feb 12, 2026
## Description

Added `TOX_DOCKER_GATEWAY` environment variable to the test workflow to
work around a `KeyError: 'Gateway'` failure in tox-docker when running
on Docker 29+.

Docker 29 [removed the deprecated top-level `NetworkSettings.Gateway`
key](https://docs.docker.com/engine/release-notes/29/) from the
container inspect API. tox-docker 5.0.0 relies on this key and crashes
with a `KeyError`. Setting `TOX_DOCKER_GATEWAY=0.0.0.0` bypasses the
broken lookup entirely.

This became flaky starting Feb 12 as the [Docker 29
rollout](actions/runner-images#13474) to
GitHub Actions runners progresses. Once complete, tests will fail 100%
of the time without this fix.

This workaround can be removed once [tox-docker merges the
fix](tox-dev/tox-docker#196).

## Motivation and Context

CI test runs on Python 3.14 (and occasionally 3.12/3.13) are failing
intermittently with:
```
tox_docker/plugin.py, line 53, in get_gateway_ip
    ip = container.attrs["NetworkSettings"]["Gateway"] or "0.0.0.0"
KeyError: 'Gateway'
```

## How Has This Been Tested?

- CI will validate that tests pass with the workaround on Docker 29+
runners

## Checklist

- [x] I have updated the documentation accordingly.
- [x] All new and existing tests passed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants