Merge pull request #143 from jphautin/add_networks_ips

add IP of networks in single view mode
This commit is contained in:
bradley 2018-09-15 10:43:22 +09:00 committed by GitHub
commit ac5bed210f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -80,6 +80,17 @@ func portsFormat(ports map[api.Port][]api.PortBinding) string {
return strings.Join(append(exposed, published...), "\n")
}
func ipsFormat(networks map[string]api.ContainerNetwork) string {
var ips []string
for k, v := range networks {
s := fmt.Sprintf("%s:%s", k, v.IPAddress)
ips = append(ips, s)
}
return strings.Join(ips, "\n")
}
func (cm *Docker) refresh(c *container.Container) {
insp := cm.inspect(c.Id)
// remove container if no longer exists
@ -89,6 +100,7 @@ func (cm *Docker) refresh(c *container.Container) {
}
c.SetMeta("name", shortName(insp.Name))
c.SetMeta("image", insp.Config.Image)
c.SetMeta("IPs", ipsFormat(insp.NetworkSettings.Networks))
c.SetMeta("ports", portsFormat(insp.NetworkSettings.Ports))
c.SetMeta("created", insp.Created.Format("Mon Jan 2 15:04:05 2006"))
c.SetMeta("health", insp.State.Health.Status)

View File

@ -6,7 +6,7 @@ import (
ui "github.com/gizak/termui"
)
var displayInfo = []string{"id", "name", "image", "ports", "state", "created", "health"}
var displayInfo = []string{"id", "name", "image", "ports", "IPs", "state", "created", "health"}
type Info struct {
*ui.Table
@ -45,7 +45,7 @@ func mkInfoRows(k, v string) (rows [][]string) {
// initial row with field name
rows = append(rows, []string{k, lines[0]})
// append any additional lines in seperate row
// append any additional lines in separate row
if len(lines) > 1 {
for _, line := range lines[1:] {
if line != "" {