Repository navigation
Offer rootless Docker next to the system daemon #14077
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
c4software
wants to merge
7
commits into
omacom:quattro
Choose a base branch
from
c4software:rootless-docker-alongside
base: quattro
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a6f62cc
Offer rootless Docker next to the system daemon
c4software bf11351
Harden rootless Docker setup and removal against partial states
c4software 4da0f83
Leave a rootless docker context that points elsewhere alone on removal
c4software 0a0e432
Check the exit status of rootless Docker setup and removal in the test
c4software 82e1cb0
Turn linger back off when rootless Docker setup is what enabled it
c4software 85e047a
Add the rootless Docker menu labels to the English catalog
c4software da2cfb6
Translate the rootless Docker menu labels and manual paragraph
c4software File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,52 @@ | ||
| #!/bin/bash | ||
|
|
||
| # omarchy:summary=Disable the rootless Docker daemon of your user | ||
|
|
||
| set -e | ||
|
|
||
| SOCKET="$XDG_RUNTIME_DIR/docker.sock" | ||
| LINGER_MARKER="$HOME/.local/state/omarchy/rootless-docker-linger" | ||
|
|
||
| # Only a context on this user's socket is ours to reset: one named rootless but | ||
| # aimed elsewhere (another socket, an SSH host) belongs to the user, just as | ||
| # setup refuses to select it. | ||
| own_context=false | ||
| if docker context inspect rootless &>/dev/null; then | ||
| context_host=$(docker context inspect rootless --format '{{.Endpoints.docker.Host}}') | ||
| if [[ $context_host == "unix://$SOCKET" ]]; then | ||
| own_context=true | ||
| else | ||
| echo "Leaving the docker context 'rootless' alone: it points to $context_host." | ||
| fi | ||
| fi | ||
|
|
||
| # Clean up whatever is left, not only an enabled unit: a unit disabled without | ||
| # --now keeps the daemon running, and the context may still be selected or the | ||
| # linger setup turned on still be in place. | ||
| if ! systemctl --user -q is-enabled docker.service 2>/dev/null \ | ||
| && ! systemctl --user -q is-active docker.service docker.socket 2>/dev/null \ | ||
| && [[ $own_context == false && ! -f $LINGER_MARKER ]]; then | ||
| echo "Rootless Docker is not enabled for $USER." | ||
| exit 0 | ||
| fi | ||
|
|
||
| systemctl --user disable --now docker.service docker.socket 2>/dev/null || true | ||
|
|
||
| if [[ $own_context == true ]]; then | ||
| docker context use default >/dev/null | ||
| docker context rm -f rootless >/dev/null | ||
| fi | ||
|
|
||
| # Only a linger setup turned on: one the user already had stays. | ||
| if [[ -f $LINGER_MARKER ]]; then | ||
| loginctl disable-linger "$USER" | ||
| rm -f "$LINGER_MARKER" | ||
| fi | ||
|
|
||
| echo "" | ||
| echo "Rootless Docker DISABLED. 'docker' talks to the system daemon again" | ||
| echo "(through sudo, unless sudoless Docker is enabled)." | ||
| echo "" | ||
| echo "Images and volumes stay in ~/.local/share/docker. They belong to subordinate" | ||
| echo "UIDs, so delete them with: rootlesskit rm -rf ~/.local/share/docker" | ||
| echo "" |
This file contains hidden or 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,103 @@ | ||
| #!/bin/bash | ||
|
|
||
| # omarchy:summary=Run a rootless Docker daemon for your user, next to the system daemon | ||
| # omarchy:requires-sudo=true | ||
|
|
||
| set -e | ||
|
|
||
| # Rootless Docker runs a second dockerd as your user, inside a user namespace: | ||
| # root in a container maps to your own account, so `docker` works without sudo | ||
| # and without the root-equivalent docker group. The system daemon keeps running | ||
| # untouched for what needs real root (the Windows VM, privileged containers), | ||
| # reached with `sudo docker` as before. The two daemons have separate images, | ||
| # volumes and networks. | ||
|
|
||
| SOCKET="$XDG_RUNTIME_DIR/docker.sock" | ||
| LINGER_MARKER="$HOME/.local/state/omarchy/rootless-docker-linger" | ||
|
|
||
| if systemctl --user -q is-enabled docker.service 2>/dev/null; then | ||
| echo "Rootless Docker is already enabled for $USER." | ||
| echo "To disable it again, run: omarchy-remove-security-rootless-docker" | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "" | ||
| echo "Rootless Docker runs a Docker daemon as your own user, next to the system one:" | ||
| echo "" | ||
| echo " docker ... your rootless daemon, no sudo, no docker group" | ||
| echo " sudo docker ... the system daemon, unchanged (Windows VM, privileged containers)" | ||
| echo "" | ||
| echo "Containers can only reach what your user can. Limits: ports below 1024 need" | ||
| echo "a sysctl, files written in bind mounts by a non-root container user land on" | ||
| echo "a subordinate UID (100000+), and images are not shared with the system daemon." | ||
| echo "" | ||
|
|
||
| if ! gum confirm "Enable rootless Docker?"; then | ||
| echo "Aborted. No changes made." | ||
| exit 0 | ||
| fi | ||
|
|
||
| if ! grep -q "^$USER:" /etc/subuid || ! grep -q "^$USER:" /etc/subgid; then | ||
| echo "No subordinate UID/GID range for $USER in /etc/subuid and /etc/subgid." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Reuse a context named rootless only when it already points at this socket: | ||
| # selecting one aimed elsewhere (another socket, an SSH host) would leave plain | ||
| # `docker` on the wrong daemon. Checked before anything is installed. | ||
| if docker context inspect rootless &>/dev/null; then | ||
| context_host=$(docker context inspect rootless --format '{{.Endpoints.docker.Host}}') | ||
| if [[ $context_host != "unix://$SOCKET" ]]; then | ||
| echo "A docker context named 'rootless' already points to $context_host." >&2 | ||
| echo "Remove or rename it (docker context rm rootless), then run this again." >&2 | ||
| exit 1 | ||
| fi | ||
| fi | ||
|
|
||
| omarchy-pkg-add rootlesskit slirp4netns | ||
| # Arch's docker package leaves out upstream's rootless script and user unit. | ||
| omarchy-pkg-aur-add docker-rootless-extras | ||
|
|
||
| # Keeps the daemon (and --restart containers) running without an open session. | ||
| # Marked only when this turns linger on, so rollback and removal turn it back | ||
| # off without taking away a linger the user already had. | ||
| if [[ $(loginctl show-user "$USER" -p Linger --value) != "yes" ]]; then | ||
| loginctl enable-linger "$USER" | ||
| mkdir -p "${LINGER_MARKER%/*}" | ||
| touch "$LINGER_MARKER" | ||
| fi | ||
|
|
||
| # The menu and a rerun read an enabled unit as a finished setup, so a failure | ||
| # from here on disables it again rather than leaving a half-done state behind. | ||
| rollback() { | ||
| echo "$1" >&2 | ||
| systemctl --user disable --now docker.service 2>/dev/null || true | ||
| if [[ -f $LINGER_MARKER ]]; then | ||
| loginctl disable-linger "$USER" || true | ||
| rm -f "$LINGER_MARKER" | ||
| fi | ||
| exit 1 | ||
| } | ||
|
|
||
| systemctl --user daemon-reload | ||
| systemctl --user enable --now docker.service || rollback "The rootless daemon did not start. See: journalctl --user -u docker" | ||
|
|
||
| for _ in {1..30}; do | ||
| [[ -S $SOCKET ]] && break | ||
| sleep 0.5 | ||
| done | ||
| [[ -S $SOCKET ]] || rollback "The rootless daemon did not start. See: journalctl --user -u docker" | ||
|
|
||
| # A context rather than DOCKER_HOST: plain `docker` picks it up, while sudo | ||
| # runs with root's own config and keeps reaching the system daemon. | ||
| if ! docker context inspect rootless &>/dev/null; then | ||
| docker context create rootless --description "Rootless Docker ($USER)" --docker "host=unix://$SOCKET" >/dev/null \ | ||
| || rollback "Could not create the rootless docker context." | ||
| fi | ||
| docker context use rootless >/dev/null || rollback "Could not select the rootless docker context." | ||
|
|
||
| echo "" | ||
| echo "Rootless Docker ENABLED. 'docker' now talks to your rootless daemon," | ||
| echo "'sudo docker' still reaches the system one." | ||
| echo "To go back to the system daemon by default: docker context use default" | ||
| echo "" | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.