Skip to content

docker ps: add "Platform" as formatting option - #6042

Merged
vvoland merged 2 commits into
docker:masterfrom
thaJeztah:carry_5804_docker_ps_platform
May 21, 2025
Merged

docker ps: add "Platform" as formatting option#6042
vvoland merged 2 commits into
docker:masterfrom
thaJeztah:carry_5804_docker_ps_platform

Conversation

@thaJeztah

@thaJeztahthaJeztah commented Apr 28, 2025

Copy link
Copy Markdown
Member
docker ps --format 'table {{.ID}}\t{{.Image}}\t{{.Command}}\t{{.RunningFor}}\t{{.Status}}\t{{.Ports}}\t{{.Names}}\t{{.Platform}}'
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES PLATFORM
e422855eac55 docker-cli-dev "/bin/bash" 12 minutes ago Up 12 minutes strange_jennings linux/arm64

- What I did

- How I did it

- How to verify it

- Human readable description for the release notes

Add `{{.Platform}}` as formatting option for `docker ps` to show the platform of the image the container is running.

- A picture of a cute animal (not mandatory but encouraged)

@codecov-commenter

codecov-commenter commented Apr 28, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 77.77778% with 2 lines in your changes missing coverage. Please review.

Project coverage is 55.03%. Comparing base (af09051) to head (67c0be4).

Additional details and impacted files
@@ Coverage Diff @@## master #6042 +/- ##
=======================================
Coverage 55.02% 55.03% =======================================
Files 361 361 Lines 30131 30140 +9 =======================================
+ Hits 16581 16588 +7 - Misses 12595 12597 +2 
Partials 955 955 
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@thaJeztah
thaJeztahforce-pushed the carry_5804_docker_ps_platform branch 2 times, most recently from f1b444d to 0441757CompareMay 13, 2025 10:58
Comment threadcli/command/formatter/container.go Outdated

func (p Platform) String() string {
if p.Platform.OS == "" {
// Prevent rendering as "unknown"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't "unknown" actually make sense here if the platform isn't known?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm... maybe yes. I think I did this because the platform could either be missing in the response or empty, but yeah, perhaps we could.

@thaJeztah
thaJeztahforce-pushed the carry_5804_docker_ps_platform branch from 0441757 to ef49b5dCompareMay 16, 2025 12:16
@thaJeztah
thaJeztahforce-pushed the carry_5804_docker_ps_platform branch 4 times, most recently from 7c82cc2 to 159c2dfCompareMay 16, 2025 15:41
Comment threadcli/command/formatter/container.go Outdated
// if p == nil || p.Platform == nil || (p.Platform.OS == "" && p.Platform.Architecture == "") {
if p == nil || p.Platform == nil {

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBD: do we want a nil platform and "zero" platform to be shown as nil, or keep it as-is to distinguish both?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A case where ImageManifestDescriptor.Platform would be nil is unexpected:

https://github.com/moby/moby/blob/master/container/view.go#L419-L425

IMO, as this is user facing string, it would be appropriate to use the unknown platform.

WDYT?

@thaJeztah
thaJeztahforce-pushed the carry_5804_docker_ps_platform branch from 159c2df to b5f1a2bCompareMay 16, 2025 19:33
@thaJeztahthaJeztah added this to the 28.2.0 milestone May 16, 2025
@thaJeztah
thaJeztah marked this pull request as ready for review May 16, 2025 19:38
@thaJeztah

Copy link
Copy Markdown
MemberAuthor

@vvoland@Benehiko ptal; it's currently 3 separate commits, but should be squashed; I wasn't sure which if the approaches made most sense; make it use a pointer so that it can have nil (which can also be used in templating to make a conditional template), or to always return a Platform (which may be "empty").

@Benehiko

Copy link
Copy Markdown
Member

I don't have a strong preference, returning nil sounds good to me

jsternbergand others added 2 commits May 21, 2025 12:43
 docker ps --format 'table {{.ID}}\t{{.Image}}{{.Command}}\t{{.RunningFor}}\t{{.Status}}\t{{.Ports}}\t{{.Names}}\t{{.Platform}}'
CONTAINER ID IMAGECOMMAND CREATED STATUS PORTS NAMES PLATFORM
e422855eac55 docker-cli-dev"/bin/bash" 12 minutes ago Up 12 minutes strange_jennings linux/arm64
Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
With this patch:
docker ps --format 'table {{.Names}}\t{{.Platform}}'
NAMES PLATFORM
optimistic_nightingale linux/arm64
mycontainer linux/arm64/v8
trusting_goldstine linux/arm64
docker ps --format '{{.Platform}}'
linux/arm64
linux/arm64/v8
linux/arm64
docker ps --format '{{json .Platform}}'
{"architecture":"arm64","os":"linux"}
{"architecture":"arm64","os":"linux","variant":"v8"}
{"architecture":"arm64","os":"linux"}
docker ps --format 'json'
{"Command":"\"/bin/bash\"","CreatedAt":"2025-05-13 10:12:19 +0000 UTC","ID":"e8b3b2d604f1","Image":"docker-cli-dev","Labels":"desktop.docker.io/binds/0/Source=/Users/thajeztah/go/src/github.com/docker/cli,desktop.docker.io/binds/0/SourceKind=hostFile,desktop.docker.io/binds/0/Target=/go/src/github.com/docker/cli,desktop.docker.io/mounts/0/Source=/var/run/docker.sock,desktop.docker.io/mounts/0/SourceKind=dockerSocketProxied,desktop.docker.io/mounts/0/Target=/var/run/docker.sock,desktop.docker.io/ports.scheme=v2","LocalVolumes":"1","Mounts":"/host_mnt/User…,docker-cli-dev…,/run/host-serv…","Names":"optimistic_nightingale","Networks":"bridge","Platform":{"architecture":"arm64","os":"linux"},"Ports":"","RunningFor":"38 minutes ago","Size":"0B","State":"running","Status":"Up 38 minutes"}
{"Command":"\"/docker-entrypoint.…\"","CreatedAt":"2025-05-13 09:58:01 +0000 UTC","ID":"c93b808dd54e","Image":"nginx:alpine","Labels":"desktop.docker.io/ports.scheme=v2,maintainer=NGINX Docker Maintainers \u003cdocker-maint@nginx.com\u003e","LocalVolumes":"0","Mounts":"","Names":"mycontainer","Networks":"bridge","Platform":{"architecture":"arm64","os":"linux","variant":"v8"},"Ports":"80/tcp","RunningFor":"53 minutes ago","Size":"0B","State":"running","Status":"Up 53 minutes"}
{"Command":"\"/usr/bin/gotty --ti…\"","CreatedAt":"2025-05-13 07:31:18 +0000 UTC","ID":"cbb981b06e46","Image":"thajeztah/dockershell:latest","Labels":"desktop.docker.io/ports.scheme=v2,com.thajeztah.docker-shell=1","LocalVolumes":"0","Mounts":"","Names":"trusting_goldstine","Networks":"bridge","Platform":{"architecture":"arm64","os":"linux"},"Ports":"0.0.0.0:55000-\u003e8080/tcp","RunningFor":"3 hours ago","Size":"0B","State":"running","Status":"Up 3 hours"}
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah

Copy link
Copy Markdown
MemberAuthor

@vvoland updated to squash the last 2 commits; PTAL

@vvolandvvoland left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@vvoland
vvoland merged commit 97e060e into docker:masterMay 21, 2025
@thaJeztah
thaJeztah deleted the carry_5804_docker_ps_platform branch May 21, 2025 12:59
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@thaJeztah@codecov-commenter@Benehiko@vvoland@jsternberg