Skip to content

Commit 38b0f84

Browse files
committed
Add "platform" column to docker ps
With this change: docker create armhf/hello-world docker create hello-world docker ps -a CONTAINER ID IMAGE PLATFORM COMMAND CREATED STATUS PORTS NAMES a020fcae5f4d hello-world linux/amd64 "/hello" 5 seconds ago Exited (0) 3 seconds ago vigorous_yalow 499a18874987 armhf/hello-world linux/arm64 "/hello" 58 seconds ago Exited (0) 57 seconds ago hardcore_brown docker ps -a --format=raw container_id: a020fcae5f4d image: hello-world platform: linux/amd64 command: "/hello" created_at: 2021-07-05 07:08:19 +0000 UTC state: exited status: Exited (0) About an hour ago names: vigorous_yalow labels: ports: container_id: 499a18874987 image: armhf/hello-world platform: linux/arm64 command: "/hello" created_at: 2021-07-05 07:07:26 +0000 UTC state: exited status: Exited (0) About an hour ago names: hardcore_brown labels: ports: docker ps -a --format '{{json .}}' | jq . { "Command": "\"/hello\"", "CreatedAt": "2021-07-05 07:08:19 +0000 UTC", "ID": "a020fcae5f4d", "Image": "hello-world", "Labels": "", "LocalVolumes": "0", "Mounts": "", "Names": "vigorous_yalow", "Networks": "bridge", "Platform": "linux/amd64", "Ports": "", "RunningFor": "52 seconds ago", "Size": "0B (virtual 13.3kB)", "State": "exited", "Status": "Exited (0) 51 seconds ago" } { "Command": "\"/hello\"", "CreatedAt": "2021-07-05 07:07:26 +0000 UTC", "ID": "499a18874987", "Image": "armhf/hello-world", "Labels": "", "LocalVolumes": "0", "Mounts": "", "Names": "hardcore_brown", "Networks": "bridge", "Platform": "linux/arm64", "Ports": "", "RunningFor": "About a minute ago", "Size": "0B (virtual 1.64kB)", "State": "exited", "Status": "Exited (0) About a minute ago" } To be discussed: what should the presentation be of platform if an "os variant" is present? For example (from `docker manifest inspect hello-world`); ```json { "mediaType": "application/vnd.docker.distribution.manifest.v2+json", "size": 1125, "digest": "sha256:90e120baffe5afa60dd5a24abcd051db49bd6aee391174da5e825ee6ee5a12a0", "platform": { "architecture": "amd64", "os": "windows", "os.version": "10.0.17763.1999" } } ``` Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 79f4224 commit 38b0f84

File tree

4 files changed

+84
-73
lines changed

4 files changed

+84
-73
lines changed

cli/command/formatter/container.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
const (
17-
defaultContainerTableFormat = "table {{.ID}}\t{{.Image}}\t{{.Command}}\t{{.RunningFor}}\t{{.Status}}\t{{.Ports}}\t{{.Names}}"
17+
defaultContainerTableFormat = "table {{.ID}}\t{{.Image}}\t{{.Platform}}\t{{.Command}}\t{{.RunningFor}}\t{{.Status}}\t{{.Ports}}\t{{.Names}}"
1818

1919
namesHeader = "NAMES"
2020
commandHeader = "COMMAND"
@@ -42,6 +42,7 @@ func NewContainerFormat(source string, quiet bool, size bool) Format {
4242
}
4343
format := `container_id: {{.ID}}
4444
image: {{.Image}}
45+
platform: {{.Platform}}
4546
command: {{.Command}}
4647
created_at: {{.CreatedAt}}
4748
state: {{- pad .State 1 0}}
@@ -92,6 +93,7 @@ func NewContainerContext() *ContainerContext {
9293
"ID": ContainerIDHeader,
9394
"Names": namesHeader,
9495
"Image": ImageHeader,
96+
"Platform": PlatformHeader,
9597
"Command": commandHeader,
9698
"CreatedAt": CreatedAtHeader,
9799
"RunningFor": runningForHeader,
@@ -294,6 +296,12 @@ func (c *ContainerContext) Networks() string {
294296
return strings.Join(networks, ",")
295297
}
296298

299+
// Platform returns formatted string representing the container image's
300+
// platform (e.g. linux/arm/v7).
301+
func (c *ContainerContext) Platform() string {
302+
return c.c.Platform.String()
303+
}
304+
297305
// DisplayablePorts returns formatted string representing open ports of container
298306
// e.g. "0.0.0.0:80->9090/tcp, 9988/tcp"
299307
// it's used by command 'docker ps'

cli/command/formatter/custom.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const (
1616
StatusHeader = "STATUS"
1717
PortsHeader = "PORTS"
1818
ImageHeader = "IMAGE"
19+
PlatformHeader = "PLATFORM"
1920
ContainerIDHeader = "CONTAINER ID"
2021
)
2122

0 commit comments

Comments
 (0)