Skip to content

Commit

Permalink
#191 Docker Compose support
Browse files Browse the repository at this point in the history
Added "compose project", "compose service", "compose config", "compose workdir" fields.
They are shown in container info view.
Since the fields may be empty so added a condition to show them only if they have a value
  • Loading branch information
stokito committed Oct 25, 2020
1 parent e1a52a3 commit 145ed61
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions connector/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ func (cm *Docker) refresh(c *container.Container) {
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)
c.SetMeta("compose project", insp.Config.Labels["com.docker.compose.project"])
c.SetMeta("compose service", insp.Config.Labels["com.docker.compose.service"])
c.SetMeta("compose config", insp.Config.Labels["com.docker.compose.project.config_files"])
c.SetMeta("compose workdir", insp.Config.Labels["com.docker.compose.project.working_dir"])
for _, env := range insp.Config.Env {
c.SetMeta("[ENV-VAR]", env)
}
Expand Down Expand Up @@ -218,5 +222,6 @@ func (cm *Docker) All() (containers container.Containers) {

// use primary container name
func shortName(name string) string {
// remove leading slash e.g. /containerName to containerName
return strings.Replace(name, "/", "", 1)
}
6 changes: 4 additions & 2 deletions cwidgets/single/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
ui "github.com/gizak/termui"
)

var displayInfo = []string{"id", "name", "image", "ports", "IPs", "state", "created", "health"}
var displayInfo = []string{"id", "name", "image", "ports", "IPs", "state", "created", "health", "compose project", "compose service", "compose config", "compose workdir"}

type Info struct {
*ui.Table
Expand All @@ -31,7 +31,9 @@ func (w *Info) Set(k, v string) {
w.Rows = [][]string{}
for _, k := range displayInfo {
if v, ok := w.data[k]; ok {
w.Rows = append(w.Rows, mkInfoRows(k, v)...)
if v != "" {
w.Rows = append(w.Rows, mkInfoRows(k, v)...)
}
}
}

Expand Down

0 comments on commit 145ed61

Please sign in to comment.