Skip to content

Conversation

@jsternberg
Copy link
Collaborator

@jsternberg jsternberg commented Feb 6, 2025

Adds platform information to containers (for docker ps).

- What I did

Added the platform to the container.Summary struct so it could be returned in /containers/json.

- How I did it

Adapted this PR for the current master and upcoming api version: #42464

As mentioned in the original PR, there's still some follow up. I'm copying and pasting that message here.

  • filter by architecture
  • perhaps a way to indicate that a container/image is non-native (useful to provide that information, so that clients don't have to replicate the "variants" such as arm/v5 running on arm64 (which is not "matching", but no emulation should be needed in that case); similarly, Windows OS versions (?)
  • check for consistency, e.g. docker inspect shows a Platform: linux, but does not contain Architecture.

The last one seems to be a potentially big issue with the name. The Platform is used instead of the name OS, but Platform in that API is the same as the OS.

- How to verify it

docker run -d --name foo nginx:alpine

curl --unix-socket /var/run/docker.sock http://localhost/containers/json | jq

- Human readable description for the release notes

`GET /containers/json` now returns an `ImageManifestDescriptor` field matching the same field in `/containers/{name}/json`. This field is only populated if the daemon provides a multi-platform image store.

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

@thaJeztah
Copy link
Member

Ah, right, I need to refresh my memory as I recall there was some back and forth on doing this and I think some considered that it was part of the image info, but it's a long time since I worked on #42464

@thaJeztah
Copy link
Member

(i.e. ISTR there was some suggestion to include the image descriptor in the response or something along those lines ... but I need to dig really deep in memory 🤣)

@jsternberg
Copy link
Collaborator Author

I did need to update the original PR a bit, but it was fewer code changes rather than more. The daemon didn't require any change because the platform had been added as a parameter at some point so it was already present.

Copy link
Contributor

@vvoland vvoland left a comment

Choose a reason for hiding this comment

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

Hmm, wondering if we should consider doing the same as we do for container inspect (/containers/.../json), where we return the full image manifest descriptor with the Platform field set.

See: #48855

@vvoland vvoland added containerd-integration Issues and PRs related to containerd integration area/api API impact/api labels Feb 10, 2025
@jsternberg
Copy link
Collaborator Author

@vvoland I'd say yes, but the Platform name is currently taken by the OS so it would be a breaking change. I'm not sure if there's a better name that can be used for it or how to resolve the breaking change.

@vvoland
Copy link
Contributor

vvoland commented Feb 10, 2025

Yes, so that would actually solve that issue. If we exposed the whole image manifest descriptor like we did in container inspect:

// ImageManifestDescriptor is the descriptor of a platform-specific manifest of the image used to create the container.
ImageManifestDescriptor *ocispec.Descriptor `json:",omitempty"`

the platform would also be a part of that descriptor:

// This should only be used when referring to a manifest.
Platform *Platform `json:"platform,omitempty"`

// Descriptor describes the disposition of targeted content.
// This structure provides `application/vnd.oci.descriptor.v1+json` mediatype
// when marshalled to JSON.
type Descriptor struct {
// MediaType is the media type of the object this schema refers to.
MediaType string `json:"mediaType"`
// Digest is the digest of the targeted content.
Digest digest.Digest `json:"digest"`
// Size specifies the size in bytes of the blob.
Size int64 `json:"size"`
// URLs specifies a list of URLs from which this object MAY be downloaded
URLs []string `json:"urls,omitempty"`
// Annotations contains arbitrary metadata relating to the targeted content.
Annotations map[string]string `json:"annotations,omitempty"`
// Data is an embedding of the targeted content. This is encoded as a base64
// string when marshalled to JSON (automatically, by encoding/json). If
// present, Data can be used directly to avoid fetching the targeted content.
Data []byte `json:"data,omitempty"`
// Platform describes the platform which the image in the manifest runs on.
//
// This should only be used when referring to a manifest.
Platform *Platform `json:"platform,omitempty"`

@jsternberg jsternberg force-pushed the containers-platform-json branch from c1ae171 to 626a3f0 Compare February 12, 2025 21:07
Comment on lines 216 to 221
if versions.LessThan(version, "1.48") {
// ImageManifestDescriptor information was added in API 1.48
for _, c := range systemDiskUsage.Containers {
c.ImageManifestDescriptor = nil
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering if we should include that in the system disk usage at all 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Good point. ISTR that one was the horrible type that was reused "for convenience", but keeps popping up?

Names []string
Image string
ImageID string
ImageManifestDescriptor *ocispec.Descriptor `json:",omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

oh! Before I blame myself; we've been very lax on specifying the intended casing of fields in JSON (depending on "whatever Go makes of it); this has resulted in inconsistencies where the Swagger documented the wrong casing (the Id one is a good example of that, where we had to later adjust the case to what it happened to be). Go itself treats JSON case-insensitive, but not all languages do (and ISTR Go is working on a "v2" JSON package to allow case-sensitivity).

Probably good to add an explicit json:"ImageManifestDescriptor,omitempty" (at least for new fields; we should also tackle existing fields at some point)

@jsternberg jsternberg force-pushed the containers-platform-json branch 3 times, most recently from 28dcca1 to 921ed17 Compare February 13, 2025 18:58
Copy link
Member

@neersighted neersighted left a comment

Choose a reason for hiding this comment

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

LGTM with CI passing.

Adds platform information to containers (for `docker ps`).

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
@jsternberg jsternberg force-pushed the containers-platform-json branch from 921ed17 to 927e07e Compare February 13, 2025 20:52
@jsternberg
Copy link
Collaborator Author

I've updated the test to only run when a multi-platform store is in use. I copied this from TestInspectImageManifestPlatform and I have also renamed the test function to match this format.

@thaJeztah thaJeztah added this to the 28.0.0 milestone Feb 13, 2025
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

@thaJeztah thaJeztah merged commit 3b8eb1e into moby:master Feb 13, 2025
162 checks passed
@jsternberg jsternberg deleted the containers-platform-json branch February 14, 2025 00:44
snapshot.NetworkSettings = &container.NetworkSettingsSummary{Networks: networks}

if ctr.ImageManifest != nil && ctr.ImageManifest.Platform == nil {
ctr.ImageManifest.Platform = &ctr.ImagePlatform
Copy link
Contributor

Choose a reason for hiding this comment

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

ctr is supposed to be immutable, we shouldn't patch it in ctr directly.

This should be patched in snapshot.Summary

Copy link
Contributor

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/api API containerd-integration Issues and PRs related to containerd integration impact/api impact/changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose platform in docker ps

4 participants