feat(run): add support for --expose and --publish-all#5036
Open
Mujib-Ahasan wants to merge 2 commits into
Open
feat(run): add support for --expose and --publish-all#5036Mujib-Ahasan wants to merge 2 commits into
--expose and --publish-all#5036Mujib-Ahasan wants to merge 2 commits into
Conversation
AkihiroSuda
reviewed
Jul 2, 2026
| // 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") |
Member
There was a problem hiding this comment.
Please update the docs too
nerdctl/docs/command-reference.md
Lines 457 to 460 in 4608753
AkihiroSuda
reviewed
Jul 2, 2026
| UTSNamespace string | ||
| // PortMappings specifies a list of ports to publish from the container to the host | ||
| PortMappings []cni.PortMapping | ||
| ExposedPorts []string |
Member
There was a problem hiding this comment.
Needs a code comment. How does it relate to PortMappings?
AkihiroSuda
reviewed
Jul 2, 2026
| // PortMappings specifies a list of ports to publish from the container to the host | ||
| PortMappings []cni.PortMapping | ||
| ExposedPorts []string | ||
| PublishAll bool |
Member
Doesn't seem covered in this PR? |
Author
will add this shortly! |
Signed-off-by: Mujib Ahasan <ahasanmujib8@gmail.com>
ec40dbe to
2212a8e
Compare
Signed-off-by: Mujib Ahasan <ahasanmujib8@gmail.com>
2212a8e to
e38f368
Compare
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.
Description
This PR adds support for the Docker compatible
--exposeand--publish-all(-P) flags tonerdctl runandnerdctl create.Previously, nerdctl supported explicit port publishing through
--publish(-p), but did not support declaring additional exposed ports with--exposeor automatically publishing all exposed ports using-P. With this change, users can expose additional container ports via the CLI, and-Pwill 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