forked from moby/moby
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow running
dockerd
in an unprivileged user namespace (rootless m…
…ode) Please refer to `docs/rootless.md`. TLDR: * Make sure `/etc/subuid` and `/etc/subgid` contain the entry for you * `dockerd-rootless.sh --experimental` * `docker -H unix://$XDG_RUNTIME_DIR/docker.sock run ...` Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
- Loading branch information
1 parent
a268955
commit d210e20
Showing
32 changed files
with
2,235 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/sh | ||
set -e -x | ||
if [ -z $XDG_RUNTIME_DIR ]; then | ||
echo "XDG_RUNTIME_DIR needs to be set" | ||
exit 1 | ||
fi | ||
if [ -z $HOME ]; then | ||
echo "HOME needs to be set" | ||
exit 1 | ||
fi | ||
|
||
if [ -z $_DOCKERD_ROOTLESS_CHILD ]; then | ||
_DOCKERD_ROOTLESS_CHILD=1 | ||
export _DOCKERD_ROOTLESS_CHILD | ||
# Re-exec the script via RootlessKit, so as to create unprivileged {user,mount,network} namespaces. | ||
# | ||
# --net specifies the network stack. slirp4netns, vpnkit, and vdeplug_slirp are supported. | ||
# Currently, slirp4netns is the fastest. | ||
# See https://github.com/rootless-containers/rootlesskit for the benchmark result. | ||
# | ||
# --copy-up allows removing/creating files in the directories by creating tmpfs and symlinks | ||
# * /etc: copy-up is required so as to prevent `/etc/resolv.conf` in the | ||
# namespace from being unexpectedly unmounted when `/etc/resolv.conf` is recreated on the host | ||
# (by either systemd-networkd or NetworkManager) | ||
# * /run: copy-up is required so that we can create /run/docker (hardcoded for plugins) in our namespace | ||
rootlesskit \ | ||
--net=slirp4netns --mtu=65520 \ | ||
--copy-up=/etc --copy-up=/run \ | ||
$0 $@ | ||
else | ||
[ $_DOCKERD_ROOTLESS_CHILD = 1 ] | ||
# remove the symlinks for the existing files in the parent namespace if any, | ||
# so that we can create our own files in our mount namespace. | ||
rm -f /run/docker /run/xtables.lock | ||
dockerd $@ | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Rootless mode (Experimental) | ||
|
||
The rootless mode allows running `dockerd` as an unprivileged user, using `user_namespaces(7)`, `mount_namespaces(7)`, `network_namespaces(7)`, and [slirp4netns](https://github.com/rootless-containers/slirp4netns). | ||
|
||
No SUID binary is required except `newuidmap` and `newgidmap`. | ||
|
||
## Requirements | ||
* `newuidmap` and `newgidmap` need to be installed on the host. These commands are provided by the `uidmap` package on most distros. | ||
|
||
* `/etc/subuid` and `/etc/subgid` should contain >= 65536 sub-IDs. e.g. `penguin:231072:65536`. | ||
|
||
```console | ||
$ id -u | ||
1001 | ||
$ whoami | ||
penguin | ||
$ grep ^$(whoami): /etc/subuid | ||
penguin:231072:65536 | ||
$ grep ^$(whoami): /etc/subgid | ||
penguin:231072:65536 | ||
``` | ||
|
||
* Some distros such as Debian (excluding Ubuntu) and Arch Linux require `sudo sh -c "echo 1 > /proc/sys/kernel/unprivileged_userns_clone"`. | ||
* Some distros require `sudo modprobe ip_tables iptable_mangle iptable_nat iptable_filter`. | ||
|
||
## Restrictions | ||
|
||
* Only `vfs` graphdriver is supported. However, on [Ubuntu](http://kernel.ubuntu.com/git/ubuntu/ubuntu-artful.git/commit/fs/overlayfs?h=Ubuntu-4.13.0-25.29&id=0a414bdc3d01f3b61ed86cfe3ce8b63a9240eba7) and a few distros, `overlay2` and `overlay` are also supported. [Starting with Linux 4.18](https://www.phoronix.com/scan.php?page=news_item&px=Linux-4.18-FUSE), we will be also able to implement FUSE snapshotters. | ||
* Cgroups (including `docker top`) and AppArmor are disabled at the moment. (FIXME: we could enable Cgroups if configured on the host) | ||
* Checkpoint is not supported at the moment. | ||
* Running rootless `dockerd` in rootless/rootful `dockerd` is also possible, but not fully tested. | ||
|
||
## Usage | ||
|
||
### Daemon | ||
|
||
You need to run `dockerd-rootless.sh` instead of `dockerd`. | ||
|
||
```console | ||
$ dockerd-rootless.sh --experimental" | ||
``` | ||
As Rootless mode is experimental per se, currently you always need to run `dockerd-rootless.sh` with `--experimental`. | ||
|
||
Remarks: | ||
* The socket path is set to `$XDG_RUNTIME_DIR/docker.sock` by default. `$XDG_RUNTIME_DIR` is typically set to `/run/user/$UID`. | ||
* The data dir is set to `~/.local/share/docker` by default. | ||
* The exec dir is set to `$XDG_RUNTIME_DIR/docker` by default. | ||
* The config dir is set to `~/.config/docker` (not `~/.docker`) by default. | ||
* The `dockerd-rootless.sh` script executes `dockerd` in its own user, mount, and network namespace. You can enter the namespaces by running `nsenter -U --preserve-credentials -n -m -t $(cat $XDG_RUNTIME_DIR/docker.pid)`. | ||
|
||
### Client | ||
|
||
You can just use the upstream Docker client but you need to set the socket path explicitly. | ||
|
||
```console | ||
$ docker -H unix://$XDG_RUNTIME_DIR/docker.sock run -d nginx | ||
``` | ||
|
||
### Exposing ports | ||
|
||
In addition to exposing container ports to the `dockerd` network namespace, you also need to expose the ports in the `dockerd` network namespace to the host network namespace. | ||
|
||
```console | ||
$ docker -H unix://$XDG_RUNTIME_DIR/docker.sock run -d -p 80:80 nginx | ||
$ socat -t -- TCP-LISTEN:8080,reuseaddr,fork EXEC:"nsenter -U -n -t $(cat $XDG_RUNTIME_DIR/docker.pid) socat -t -- STDIN TCP4\:127.0.0.1\:80" | ||
``` | ||
|
||
In future, `dockerd` will be able to expose the ports automatically. See https://github.com/rootless-containers/rootlesskit/issues/14 . | ||
|
||
### Routing ping packets | ||
|
||
To route ping packets, you need to set up `net.ipv4.ping_group_range` properly as the root. | ||
|
||
```console | ||
$ sudo sh -c "echo 0 2147483647 > /proc/sys/net/ipv4/ping_group_range" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/sh | ||
|
||
|
||
ROOTLESSKIT_COMMIT=d843aadf00d72082fd7a31572ef018d1e792535f | ||
|
||
install_rootlesskit() { | ||
case "$1" in | ||
"dynamic") | ||
install_rootlesskit_dynamic | ||
return | ||
;; | ||
"") | ||
export CGO_ENABLED=0 | ||
_install_rootlesskit | ||
;; | ||
*) | ||
echo 'Usage: $0 [dynamic]' | ||
;; | ||
esac | ||
} | ||
|
||
install_rootlesskit_dynamic() { | ||
export ROOTLESSKIT_LDFLAGS="-linkmode=external" install_rootlesskit | ||
export BUILD_MODE="-buildmode=pie" | ||
_install_rootlesskit | ||
} | ||
|
||
_install_rootlesskit() { | ||
echo "Install rootlesskit version $ROOTLESSKIT_COMMIT" | ||
git clone https://github.com/rootless-containers/rootlesskit.git "$GOPATH/src/github.com/rootless-containers/rootlesskit" | ||
cd "$GOPATH/src/github.com/rootless-containers/rootlesskit" | ||
git checkout -q "$ROOTLESSKIT_COMMIT" | ||
go build $BUILD_MODE -ldflags="$ROOTLESSKIT_LDFLAGS" -o ${PREFIX}/rootlesskit github.com/rootless-containers/rootlesskit/cmd/rootlesskit | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.