12 Commits

Author SHA1 Message Date
Akihiro Suda
84aedb8055 rootless: support detach-netns mode
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 <akihiro.suda.cz@hco.ntt.co.jp>
2026-04-10 02:02:51 +09:00
Sebastiaan van Stijn
38c77a9189 daemon/libnetwork/ns: make NetlinkSocketsTimeout a const
It's never updated, so let's make it clear that that's the case.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-03-29 19:51:20 +02:00
Sebastiaan van Stijn
5378f5427f daemon/libnetwork/ns: remove ParseHandlerInt, add NsHandle
It's more transparent for the caller to handle conversion.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-03-29 19:51:20 +02:00
Sebastiaan van Stijn
af73684bc3 daemon/libnetwork/ns: use sync.OnceValues
This avoids depending on global state in the package, and "forces"
consumers to go through the initHandles() func to get the handles.

A slight change in behavior is that `ResetHandles()` may now initialize
a new namespace only to reset it, but this is likely an "OK" trade-off.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-03-29 19:51:20 +02:00
Sebastiaan van Stijn
635f4c3dc4 daemon/libnetwork/ns: remove windows stub
This reverts commit 40b6ebfe75 ([libnetwork@d82ceca]),
which added it to make compile work on Windows, but this package contains
no Windows code, so shouldn't be imported in any file compiled on Windows.

[libnetwork@d82ceca]: d82ceca3f6

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-03-29 19:51:19 +02:00
Sebastiaan van Stijn
579280d444 daemon/libnetwork/ns: suppress some unhandled errors
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-03-29 19:51:17 +02:00
jokemanfire
dee7411f05 fix(libnetwork): nil pointer will cause panic
make panic info more useful

Signed-off-by: jokemanfire <hu.dingyang@zte.com.cn>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-03-29 15:35:07 +02:00
Rob Murray
362d4d9538 testutil:SetupTestOSContext - don't leak namespaces, netlink handles
SetupTestOSContextEx calls 'ns.Init' (which, outside tests, is protected
by a sync.Once), and it's called again by the returned OSContext.Cleanup
method. That overwrites the ns package's namespace and netlink handles
(initNs and initNl) without closing them.

Because SetupTestOSContextEx changes that shared state, it should not
be used in parallel tests. So, rather than trying to close the handles
in ns.Init if already open - un-export Init so it's always called via
its sync.Once, and add a reset function for tests to use. Have
SetupTestOSContextEx claim a mutex to avoid crashy surprises or
hard to catch issues where the ns package isn't using the expected
namespace if it is used in parallel tests.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-09-23 16:16:00 +01:00
Derek McGowan
f74e5d48b3 Create github.com/moby/moby/v2 module
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-31 10:13:29 -07:00
Derek McGowan
713d7f5ed1 Move internal/nlwrap to daemon/libnetwork/nlwrap
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-24 12:13:58 -07:00
Derek McGowan
3b5f7c2a29 Move internal/modprobe to daemon/libnetwork/internal/modprobe
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-14 09:25:55 -07:00
Derek McGowan
7a720df61f Move libnetwork to daemon/libnetwork
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-14 09:25:23 -07:00