Skip to content

feat(run): add support for --expose and --publish-all#5036

Open
Mujib-Ahasan wants to merge 2 commits into
containerd:mainfrom
Mujib-Ahasan:expose-publish-all-flag
Open

feat(run): add support for --expose and --publish-all#5036
Mujib-Ahasan wants to merge 2 commits into
containerd:mainfrom
Mujib-Ahasan:expose-publish-all-flag

Conversation

@Mujib-Ahasan

Copy link
Copy Markdown

Description

This PR adds support for the Docker compatible --expose and --publish-all (-P) flags to nerdctl run and nerdctl create.

Previously, nerdctl supported explicit port publishing through --publish (-p), but did not support declaring additional exposed ports with --expose or automatically publishing all exposed ports using -P. With this change, users can expose additional container ports via the CLI, and -P will publish both image defined (EXPOSE) and cli defined (--expose) ports to automatically allocated host ports by reusing the existing port mapping implementation. This improves Docker CLI compatibility while preserving the existing behaviors.

Fixes: #4689

// publish is defined as StringSlice, not StringArray, to allow specifying "--publish=80:80,443:443" (compatible with Podman)
cmd.Flags().StringSliceP("publish", "p", nil, "Publish a container's port(s) to the host")
cmd.Flags().StringSlice("expose", nil, "Expose a port or a range of ports")
cmd.Flags().BoolP("publish-all", "P", false, "Publish all exposed ports to random ports")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please update the docs too

Unimplemented `docker run` flags:
`--device-cgroup-rule`, `--disable-content-trust`, `--expose`,
`--health-start-interval`, `--link*`, `--publish-all`, `--storage-opt`,
`--volume-driver`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also needs tests

UTSNamespace string
// PortMappings specifies a list of ports to publish from the container to the host
PortMappings []cni.PortMapping
ExposedPorts []string

@AkihiroSuda AkihiroSuda Jul 2, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Needs a code comment. How does it relate to PortMappings?

// PortMappings specifies a list of ports to publish from the container to the host
PortMappings []cni.PortMapping
ExposedPorts []string
PublishAll bool

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Needs a code comment

@AkihiroSuda

Copy link
Copy Markdown
Member

image defined (EXPOSE)

Doesn't seem covered in this PR?

@AkihiroSuda AkihiroSuda left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Needs tests

@Mujib-Ahasan

Copy link
Copy Markdown
Author

Doesn't seem covered in this PR?

will add this shortly!

Signed-off-by: Mujib Ahasan <ahasanmujib8@gmail.com>
@Mujib-Ahasan Mujib-Ahasan force-pushed the expose-publish-all-flag branch from ec40dbe to 2212a8e Compare July 6, 2026 19:04
Signed-off-by: Mujib Ahasan <ahasanmujib8@gmail.com>
@Mujib-Ahasan Mujib-Ahasan force-pushed the expose-publish-all-flag branch from 2212a8e to e38f368 Compare July 6, 2026 19:22
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.

Feature Request: Support --expose and --publish-all (-P) flags in nerdctl run

2 participants