Skip to content

feat: add missing HostConfig fields to dockercompat inspect response#4850

Open
ayush-panta wants to merge 1 commit intocontainerd:mainfrom
ayush-panta:enrich-inspect
Open

feat: add missing HostConfig fields to dockercompat inspect response#4850
ayush-panta wants to merge 1 commit intocontainerd:mainfrom
ayush-panta:enrich-inspect

Conversation

@ayush-panta
Copy link
Copy Markdown

This PR populates missing HostConfig fields in the dockercompat inspect response, bringing nerdctl inspect --mode=dockercompat closer to what consumers expect from Docker's GET /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, and Annotations. Ulimits are converted from OCI RLIMIT_* format to Docker's lowercase format (inverse of run_ulimit_linux.go). Annotations are filtered to exclude nerdctl/ prefixed internal entries.

Label-based fields: NetworkMode (from nerdctl/networks), RestartPolicy (parsed from containerd.io/restart.policy via restart.NewPolicy()), and AutoRemove (from nerdctl/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/privileged label at creation time and read it back at inspect. This required minor additions to create.go and labels.go.

CapAdd/CapDrop: nerdctl doesn't persist the original --cap-add/--cap-drop flags; 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:

  • Unit: TestGetCapabilitiesFromNative (7 cases), TestGetUlimitsFromNative (4 cases), extended "container from nerdctl" in TestContainerFromNative with all new fields.
  • Integration: extended TestContainerInspectHostConfig with resource and label flags + assertions, extended TestContainerInspectHostConfigDefaults with zero-value checks. Added TestContainerInspectHostConfigPrivileged (rootful only) and TestContainerInspectHostConfigCapabilities as separate tests since privileged requires root and conflicts with cap flags.

Comment thread cmd/nerdctl/container/container_inspect_linux_test.go Outdated
@ayush-panta ayush-panta force-pushed the enrich-inspect branch 2 times, most recently from eda92da to cb3ce92 Compare April 16, 2026 07:47
Signed-off-by: ayush-panta <ayushkp@amazon.com>
@ayush-panta
Copy link
Copy Markdown
Author

CI is green on relevant tests; remaining failures seem to be due to flakiness/are unrelated to my changes. Ready for review.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants