feat: add missing HostConfig fields to dockercompat inspect response#4850
Open
ayush-panta wants to merge 1 commit intocontainerd:mainfrom
Open
feat: add missing HostConfig fields to dockercompat inspect response#4850ayush-panta wants to merge 1 commit intocontainerd:mainfrom
ayush-panta wants to merge 1 commit intocontainerd:mainfrom
Conversation
AkihiroSuda
reviewed
Apr 16, 2026
eda92da to
cb3ce92
Compare
Signed-off-by: ayush-panta <ayushkp@amazon.com>
cb3ce92 to
86e8e50
Compare
Author
|
CI is green on relevant tests; remaining failures seem to be due to flakiness/are unrelated to my changes. Ready for review. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR populates missing
HostConfigfields in the dockercompat inspect response, bringingnerdctl inspect --mode=dockercompatcloser to what consumers expect from Docker'sGET /containers/{id}/json.All data comes from sources already available in
ContainerFromNative()via the OCI spec and container labels.OCI spec fields:
PidsLimit,Ulimits,MemoryReservation,MemorySwappiness, andAnnotations. Ulimits are converted from OCIRLIMIT_*format to Docker's lowercase format (inverse ofrun_ulimit_linux.go). Annotations are filtered to excludenerdctl/prefixed internal entries.Label-based fields:
NetworkMode(fromnerdctl/networks),RestartPolicy(parsed fromcontainerd.io/restart.policyviarestart.NewPolicy()), andAutoRemove(fromnerdctl/auto-remove). These labels already exist — we're just populating the fields.Privileged: The OCI spec doesn't store a "privileged" flag; it just applies all caps and device access. Inferring that from the spec is fragile, so we store a
nerdctl/privilegedlabel at creation time and read it back at inspect. This required minor additions tocreate.goandlabels.go.CapAdd/CapDrop: nerdctl doesn't persist the original
--cap-add/--cap-dropflags; only the resulting OCI bounding set survives. We reconstruct by diffing the bounding set against containerd's 14 default capabilities (containerd source, moby source — same set). Caps in bounding but not in defaults → CapAdd. Defaults not in bounding → CapDrop. There's a slight difference from Docker when --cap-add ALL is used: Docker stores and returns the literal ["ALL"], while we show the expanded list since we only have the OCI spec. This is functionally equivalent.Testing:
TestGetCapabilitiesFromNative(7 cases),TestGetUlimitsFromNative(4 cases), extended "container from nerdctl" inTestContainerFromNativewith all new fields.TestContainerInspectHostConfigwith resource and label flags + assertions, extendedTestContainerInspectHostConfigDefaultswith zero-value checks. AddedTestContainerInspectHostConfigPrivileged(rootful only) andTestContainerInspectHostConfigCapabilitiesas separate tests since privileged requires root and conflicts with cap flags.