Skip to content

[docker-29.x backport] daemon: disallow container port 0#51695

Merged
thaJeztah merged 1 commit into
moby:docker-29.xfrom
vvoland:51684-docker-29.x
Dec 11, 2025
Merged

[docker-29.x backport] daemon: disallow container port 0#51695
thaJeztah merged 1 commit into
moby:docker-29.xfrom
vvoland:51684-docker-29.x

Conversation

@vvoland

@vvoland vvoland commented Dec 11, 2025

Copy link
Copy Markdown
Contributor

- What I did

Although container port 0 is invalid, it's currently accepted by the Engine. Users could mistakenly declare -p 0:0 and end up with a port mapping that does nothing. In that case, the Engine would allocate an ephemeral host port and create an iptables / nftables rule that DNAT to container port 0. This is obviously wrong.

Chain DOCKER (2 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 DNAT       6    --  !docker0 *       0.0.0.0/0            0.0.0.0/0            tcp dpt:32768 to:172.18.0.2:0

Instead of failing silently, return an error message to the API client when it calls the ContainerCreate endpoint.

- Human readable description for the release notes

Return an error when a container is created with a port-mapping pointing to container port 0.

Signed-off-by: Albin Kerouanton <albin.kerouanton@docker.com>
(cherry picked from commit 43780fe)
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>

@thaJeztah thaJeztah 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.

LGTM

@thaJeztah thaJeztah merged commit bae170e into moby:docker-29.x Dec 11, 2025
198 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants