Skip to content

cli/command/container: don't silently drop invalid --ip and --link-local-ip values - #7335

Open
breken-ai wants to merge 2 commits into
docker:masterfrom
breken-ai:fix-run-ip-flags-silently-dropped
Open

breken-ai wants to merge 2 commits into
docker:masterfrom
breken-ai:fix-run-ip-flags-silently-dropped

Conversation

@breken-ai

@breken-ai breken-ai commented Sep 25, 2026 •

Copy link
Copy Markdown

Summary

docker run / docker create silently drop some static network addresses instead of reporting an error. Both cases started in v29.0.0, in the move to netip (f81816e). Before that change the values were sent as strings, and the daemon rejected invalid ones.

1. --ip with an IPv6 address is ignored

applyContainerOptions converts the value with netip.AddrFromSlice(copts.ipv4Address.To4()) and only sets it if ok. For an IPv6 value To4() returns nil, so the address is skipped:

$ docker run --network mynet --ip 2001:db8::5 alpine
# no error; the container gets a dynamically assigned address

--ip6 with an IPv4 value was not silently dropped: it was sent as ::ffff:172.20.88.22, and the daemon rejected it as "invalid IPv6 address: ::ffff:172.20.88.22". For symmetry, and for a clearer message, it is now rejected on the client too.

docker network connect --ip is not affected. It keeps the family mismatch and lets the daemon reject it.

2. An invalid --link-local-ip is ignored

--link-local-ip has no validator (opts.NewListOpts(nil)), and toNetipAddrSlice skips any value that netip.ParseAddr cannot parse. A typo such as --link-local-ip 169.254.1.1000 is dropped, and the container is created without it. The flag now uses opts.ValidateIPAddress, the same validator --dns uses, so the error appears when the flags are parsed.

The two fixes are separate commits.

Tests

The new TestParseNetworkConfig cases (invalid-ip-is-ipv6, invalid-ip6-is-ipv4, invalid-link-local-ip) fail on master (7fc2dff) with expected an error, got nil, and pass with this change. go test ./cli/command/container/ ./cli/command/network/ ./opts/ passes. gofmt and go vet are clean.

Release notes (optional)

Fix `docker run` and `docker create` silently ignoring an IPv6 address passed to `--ip` or an invalid `--link-local-ip` value.

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

🦦


Created with: Claude Code. The commits carry an Assisted-By trailer, following the AI policy in moby/moby CONTRIBUTING.md.

Since the move to netip (v29.0.0), applyContainerOptions converted the
--ip value with To4() and silently skipped it when the conversion failed.
Passing an IPv6 address to --ip, for example:

    docker run --network mynet --ip 2001:db8::5 alpine

no longer produced an error; the address was dropped, and the container
started with a dynamically assigned address instead of failing. Before
v29 the value was sent as-is, and the daemon rejected it.

Return an invalid-parameter error for an --ip value that is not IPv4,
and for an --ip6 value that is IPv4 (which was previously sent as an
IPv4-mapped IPv6 address).

Assisted-By: Claude Code
Signed-off-by: breken-ai <312387581+breken-ai@users.noreply.github.com>
The --link-local-ip flag had no validator, and since the move to netip
(v29.0.0) its values are converted with toNetipAddrSlice, which skips
any value it cannot parse. A mistyped address, for example:

    docker run --network mynet --link-local-ip 169.254.1.1000 alpine

was silently dropped, and the container was created without it. Before
v29 the value was sent as-is, and the daemon rejected it.

Validate the flag with opts.ValidateIPAddress, the same validator the
--dns flag uses, so an invalid value fails when the flags are parsed.

Assisted-By: Claude Code
Signed-off-by: breken-ai <312387581+breken-ai@users.noreply.github.com>
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.

1 participant