fix: read the container IP from NetworkSettings.Networks - #479
Merged
Conversation
container_ip_address asked docker inspect for
'{{ .NetworkSettings.IPAddress }}'. That top-level field was only ever
populated for the default bridge, and Docker 29 removed it. Asking for a field
that is gone does not return empty -- Go's template engine fails the whole
inspect:
template parsing error: template: :1:19: executing "" at
<.NetworkSettings.IPAddress>: map has no entry for key "IPAddress"
On Docker 29.7.2 NetworkSettings carries only Networks, Ports, SandboxID and
SandboxKey. The container's address lives in Networks, one entry per attached
network.
container_ip_address is reached whenever use_internal_docker_network is set,
which is how the driver is meant to be run from inside another container, so
that option is broken outright on Docker 29. Reproduced with kitchen create:
docker inspect --format '{{ .NetworkSettings.IPAddress }}' 7cf7e9ef2988...
template parsing error: ... map has no entry for key "IPAddress"
Message: Error getting internal IP of Docker container
Read from Networks instead, which has been present since Docker 1.9 and so
works on old and new daemons alike. It also fixes a case that was already
broken before the field was removed: containers on a user-defined network never
had a top-level IPAddress, only a per-network one.
The address is picked by parsing rather than by taking the first word, so a
warning docker writes to stderr is not returned as an address, and output
carrying no address raises instead of yielding "" to be recorded as the
instance hostname.
Verified against Docker 29.7.2 after the change: the driver's address matches
docker's own on the default bridge and on a user-defined network, and
kitchen create with use_internal_docker_network records the real container IP.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
tas50
force-pushed
the
fix/container-ip-address
branch
from
August 23, 2026 16:19
11b8ce7 to
43d423d
Compare
Member
Author
|
Rebased onto The spec file conflicted because #476's Re-verified after the rebase, against Docker 29.7.2: And end to end, with the merged #476/#477 destroy changes now underneath it: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
container_ip_addressaskeddocker inspectfor the top-level field:Docker 29 removed that field. On 29.7.2,
NetworkSettingscarries only:Asking for a field that is gone does not quietly return empty — Go's template engine fails the entire inspect:
What it breaks
container_ip_addressis reached wheneveruse_internal_docker_networkis set — the documented way to run this driver from inside another container. That option is therefore broken outright on Docker 29. Reproduced with a realkitchen create:It also fixes a case that was broken before the removal: a container on a user-defined network never had a top-level
IPAddress— only a per-network one — sorun_options: --network=…plususe_internal_docker_networkfailed on older daemons too.The fix
Read
NetworkSettings.Networks, which has been present since Docker 1.9 and so works on old and new daemons alike:The address is picked by parsing each token with
IPAddrrather than taking the first word, so a warning on stderr is not returned as an address — a mistake this codebase has made before. Output carrying no address now raises, instead of yielding""to be recorded as the instance hostname and failing far from the cause.A container on several networks has an address on each; the first is used, which is the only one in the single-network case this option exists for.
Verified against Docker 29.7.2
And the
kitchen createthat failed above:Specs
New cases in
spec/container_helper_spec.rb: the address is returned,Networksis asked for andIPAddressis not, the first of several networks wins, IPv6 works, a stderr warning is ignored, no address raises, and a failed inspect raises.🤖 Generated with Claude Code