Use more generic expression to fetch container IP addresses.

The IP address has been moved in newer versions of Docker but this expression will fetch the IP address from the old or new location.
This commit is contained in:
David Steele
2026-01-10 19:13:55 +07:00
parent 85caeda4e5
commit 35505d63fd
2 changed files with 8 additions and 2 deletions
+4 -1
View File
@@ -67,7 +67,10 @@ sub new
{bSuppressStdErr => true});
# Get IP Address
$self->{strIP} = trim(executeTest("docker inspect --format '\{\{ .NetworkSettings.IPAddress \}\}' $self->{strContainer}"));
$self->{strIP} = trim(
executeTest(
"docker inspect --format '\{\{range .NetworkSettings.Networks\}\}\{\{.IPAddress\}\}\{\{end\}\}'" .
" $self->{strContainer}"));
$self->{bActive} = true;
# Return from function and log return values if any
+4 -1
View File
@@ -187,7 +187,10 @@ hrnHostNew(const StringId id, const String *const container, const String *const
// Get IP address
const String *const ip = strTrim(
execOneP(strNewFmt("docker inspect --format '{{ .NetworkSettings.IPAddress }}' %s", strZ(hrnHostContainer(this)))));
execOneP(
strNewFmt(
"docker inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' %s",
strZ(hrnHostContainer(this)))));
MEM_CONTEXT_PRIOR_BEGIN()
{