diff --git a/command/formatter/stats.go b/command/formatter/stats.go index a37e9d7923..0e31792c4f 100644 --- a/command/formatter/stats.go +++ b/command/formatter/stats.go @@ -149,8 +149,10 @@ func (c *containerStatsContext) Container() string { func (c *containerStatsContext) Name() string { c.AddHeader(nameHeader) - name := c.s.Name[1:] - return name + if len(c.s.Name) > 1 { + return c.s.Name[1:] + } + return "--" } func (c *containerStatsContext) ID() string { diff --git a/command/formatter/stats_test.go b/command/formatter/stats_test.go index d5a17cc70e..f5c6cae0c3 100644 --- a/command/formatter/stats_test.go +++ b/command/formatter/stats_test.go @@ -69,6 +69,12 @@ func TestContainerStatsContextWrite(t *testing.T) { `MEM USAGE / LIMIT 20 B / 20 B -- / -- +`, + }, + { + Context{Format: "{{.Container}} {{.ID}} {{.Name}}"}, + `container1 abcdef foo +container2 -- `, }, { @@ -83,6 +89,8 @@ container2 -- stats := []StatsEntry{ { Container: "container1", + ID: "abcdef", + Name: "/foo", CPUPercentage: 20, Memory: 20, MemoryLimit: 20,