mirror of
https://github.com/fosrl/newt.git
synced 2026-03-07 03:06:42 +00:00
added use of hostname if available
This commit is contained in:
@@ -26,6 +26,8 @@ type Container struct {
|
|||||||
Labels map[string]string `json:"labels"`
|
Labels map[string]string `json:"labels"`
|
||||||
Created int64 `json:"created"`
|
Created int64 `json:"created"`
|
||||||
Networks map[string]Network `json:"networks"`
|
Networks map[string]Network `json:"networks"`
|
||||||
|
Hostname string `json:"hostname"` // added to use hostname if available instead of network address
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Port represents a port mapping for a Docker container
|
// Port represents a port mapping for a Docker container
|
||||||
@@ -173,6 +175,14 @@ func ListContainers(socketPath string, enforceNetworkValidation bool) ([]Contain
|
|||||||
// Short ID like docker ps
|
// Short ID like docker ps
|
||||||
shortId := c.ID[:12]
|
shortId := c.ID[:12]
|
||||||
|
|
||||||
|
// Inspect container to get hostname
|
||||||
|
hostname := ""
|
||||||
|
containerInfo, err := cli.ContainerInspect(ctx, c.ID)
|
||||||
|
if err == nil && containerInfo.Config != nil {
|
||||||
|
hostname = containerInfo.Config.Hostname
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Skip host container if set
|
// Skip host container if set
|
||||||
if hostContainerId != "" && c.ID == hostContainerId {
|
if hostContainerId != "" && c.ID == hostContainerId {
|
||||||
continue
|
continue
|
||||||
@@ -238,6 +248,7 @@ func ListContainers(socketPath string, enforceNetworkValidation bool) ([]Contain
|
|||||||
Labels: c.Labels,
|
Labels: c.Labels,
|
||||||
Created: c.Created,
|
Created: c.Created,
|
||||||
Networks: networks,
|
Networks: networks,
|
||||||
|
Hostname: hostname, // added
|
||||||
}
|
}
|
||||||
|
|
||||||
dockerContainers = append(dockerContainers, dockerContainer)
|
dockerContainers = append(dockerContainers, dockerContainer)
|
||||||
|
|||||||
Reference in New Issue
Block a user