Skip to content

PublishAllPorts: don't crash with nil PortBindings#51621

Merged
thaJeztah merged 1 commit intomoby:masterfrom
robmry:fix-crash-with-nil-portbindings
Dec 1, 2025
Merged

PublishAllPorts: don't crash with nil PortBindings#51621
thaJeztah merged 1 commit intomoby:masterfrom
robmry:fix-crash-with-nil-portbindings

Conversation

@robmry
Copy link
Contributor

@robmry robmry commented Nov 29, 2025

- What I did

- How I did it

- How to verify it

- Human readable description for the release notes

- Prevent a crash when making an API request with `HostConfig.PublishAllPorts` set (`-P`), and no port bindings

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

@robmry robmry added this to the 29.1.2 milestone Nov 29, 2025
@robmry robmry requested a review from thaJeztah November 29, 2025 16:45
Introduced by commit 85b260f ("PublishAllPorts: create
port mappings for exposed ports").

Signed-off-by: Rob Murray <rob.murray@docker.com>
@robmry robmry force-pushed the fix-crash-with-nil-portbindings branch from eb9888f to 7517464 Compare November 29, 2025 19:43
Comment on lines +2150 to +2151
imgWithExpose := container.WithImage(build.Do(ctx, t, c,
fakecontext.New(t, "", fakecontext.WithDockerfile("FROM busybox\nEXPOSE 80/tcp\n"))))
Copy link
Member

Choose a reason for hiding this comment

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

Silly question; does this require the image to have the exposed ports set, or would the same work when creating the container with --expose ?

(Mostly looking if we can avoid using docker build as part of test preparation if it's not needed)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The same should work for a container --expose ... I did it this way because the build command in the test was trivial, and it seemed more likely to be testing something a user would do (I'm guessing --expose with a -P on the container is unusual, compared with -p).

The test runs in < 1s, but the build is a bit log-spammy. Can change it, or test both ways?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, either way is probably fine; I recall we had some cases where the build itself was more problematic than the test.

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

left one question, but definitely not a blocker

@thaJeztah thaJeztah merged commit 4ff8942 into moby:master Dec 1, 2025
188 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

panic: "assignment to entry in nil map" in daemon/network.go during start with PublishAllPorts=true

5 participants