Skip to content

rootless: properly support --net=host and localhost registries#47103

Merged
AkihiroSuda merged 1 commit intomoby:masterfrom
AkihiroSuda:detach-netns
Apr 25, 2026
Merged

rootless: properly support --net=host and localhost registries#47103
AkihiroSuda merged 1 commit intomoby:masterfrom
AkihiroSuda:detach-netns

Conversation

@AkihiroSuda
Copy link
Copy Markdown
Member

@AkihiroSuda AkihiroSuda commented Jan 18, 2024

Now dockerd-rootless.sh launches RootlessKit with --detach-netns
so as to run the daemon in the host network namespace.

The libnetwork namespaces are allocated inside the "detached" netns
($ROOTLESSKIT_STATE_DIR/netns) that is associated with slirp4netns,
vpnkit, pasta, etc., as the rootless daemon has no CAP_NET_ADMIN for
the host network namespace.

This will enable:

  • Accelerated (and deflaked) docker pull, docker push, docker build, etc
  • Proper support for docker pull 127.0.0.1:.../...
  • Proper support for dockern run --net=host

See also:

NOTE: libnetwork contains code generated by Claude Code


- What I did

  • Accelerated (and deflaked) docker pull, docker push, docker build, etc
  • Proper support for docker pull 127.0.0.1:.../...
  • Proper support for dockern run --net=host

- How I did it
Execute the rootless daemon in the host network namespace.

Prior to this PR, the daemon was executed in a network namespace created by RootlessKit.

- How to verify it
CI should be green

- Description for the changelog

rootless: Properly support `--net=host` and localhost registries

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

@AkihiroSuda AkihiroSuda added kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. area/networking Networking impact/changelog area/rootless Rootless Mode labels Jan 18, 2024
@AkihiroSuda AkihiroSuda added this to the 26.0.0 milestone Jan 18, 2024
Comment thread contrib/dockerd-rootless.sh
@AkihiroSuda AkihiroSuda force-pushed the detach-netns branch 2 times, most recently from 625ffe3 to 9110315 Compare January 18, 2024 13:31
@AkihiroSuda

This comment was marked as resolved.

@vvoland vvoland modified the milestones: 26.0.0, v-future Feb 26, 2024
@AkihiroSuda AkihiroSuda force-pushed the detach-netns branch 2 times, most recently from c93736a to 0cf5b8d Compare October 21, 2024 12:18
@AkihiroSuda AkihiroSuda mentioned this pull request Oct 21, 2024
@AkihiroSuda

This comment was marked as duplicate.

@AkihiroSuda

This comment was marked as resolved.

@AkihiroSuda
Copy link
Copy Markdown
Member Author

Changed the milestone; assuming this is not a breaking change, right?

Assumed so, but Hyrum's Law may potentially apply 🤷‍♂️

@thaJeztah
Copy link
Copy Markdown
Member

Yeah, I think we should be able to ignore Hyrum for now; we'll see if there's a large outcry

Oh! Let me put this on the v29.3.2 milestone; I think we'll be renaming that one (easier than "moving")

@thaJeztah thaJeztah modified the milestones: 29.4.0, 29.3.2 Apr 1, 2026
Copy link
Copy Markdown
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.

🙈 left some comments; let me know what you think. Could also use input from others 😅

Comment on lines +136 to +143
// For rootless + host netns, we can't mount sysfs.
// We can't (non-recursively) bind mount /sys, either.
//
// TODO: consider to just rbind /sys from the host with rro,
// when rro is available (kernel >= 5.12, runc >= 1.1).
//
// Relevant: https://github.com/moby/buildkit/blob/v0.12.4/util/rootless/specconv/specconv_linux.go#L15-L34
// https://github.com/containerd/nerdctl/pull/2723
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.

Thanks for the comments with links; always useful as bread-crumb ❤️

Should we create a tracking-ticket for the TODO? (kernel-versions came up recently; we should probably look if we can do feature-detection if we don't have that yet, but also look what distros are still on < v5(.12)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, let's open a tracking ticket when this PR is merged

Comment thread daemon/internal/rootless/specconv/specconv_linux.go
Comment thread daemon/internal/rootless/rootless_linux.go Outdated
Comment thread daemon/libnetwork/internal/nftables/nft_exec_linux.go Outdated
Comment thread daemon/libnetwork/internal/nftables/nft_exec_linux.go
Comment thread daemon/internal/rootless/rootless_linux.go Outdated
Comment thread daemon/libnetwork/osl/namespace_linux.go
Comment thread daemon/apparmor_default.go
Comment thread daemon/internal/rootless/rootless_others.go Outdated
Comment thread daemon/container_operations.go
@vvoland vvoland modified the milestones: 29.4.0, 29.5.0 Apr 3, 2026
@AkihiroSuda AkihiroSuda force-pushed the detach-netns branch 3 times, most recently from 662078a to 6ead1b0 Compare April 3, 2026 11:12
Comment thread daemon/daemon_unix.go
Copy link
Copy Markdown
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

@vvoland @robmry PTAL

@AkihiroSuda
Copy link
Copy Markdown
Member Author

AkihiroSuda commented Apr 3, 2026

Comment thread contrib/dockerd-rootless.sh Outdated
Comment thread daemon/libnetwork/internal/nftables/nft_exec_linux.go Outdated
Now `dockerd-rootless.sh` launches RootlessKit with `--detach-netns`
so as to run the daemon in the host network namespace.

The libnetwork namespaces are allocated inside the "detached" netns
(`$ROOTLESSKIT_STATE_DIR/netns`) that is associated with slirp4netns,
vpnkit, pasta, etc., as the rootless daemon has no `CAP_NET_ADMIN` for
the host network namespace.

This will enable:
- Accelerated (and deflaked) `docker pull`, `docker push`, `docker build`, etc
- Proper support for `docker pull 127.0.0.1:.../...`
- Proper support for `dockern run --net=host`

See also:
- rootless-containers/rootlesskit PR 379
- containerd/nerdctl PR 2723

NOTE: libnetwork contains code generated by Claude Code

Signed-off-by: Akihiro Suda <[email protected]>
Copy link
Copy Markdown
Contributor

@vvoland vvoland left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@AkihiroSuda AkihiroSuda requested a review from thaJeztah April 13, 2026 23:35
@AkihiroSuda AkihiroSuda requested a review from vvoland April 24, 2026 22:21
@AkihiroSuda AkihiroSuda merged commit b8dffa4 into moby:master Apr 25, 2026
185 checks passed
@AkihiroSuda
Copy link
Copy Markdown
Member Author

AkihiroSuda commented Apr 25, 2026

Merged, as the PR has been approved and the master branch is now thawed for v29.5.

Docs PR:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/contrib area/daemon Core Engine area/networking Networking area/packaging area/rootless Rootless Mode area/security/apparmor area/security impact/changelog kind/enhancement Enhancements are not bugs or new features but can improve usability or performance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--net host does not allow access to open sockets with rootless Docker, except from other containers on the same host

3 participants