Skip to content

Commit

Permalink
Merge pull request #44218 from thaJeztah/20.10_backport_more_robust_r…
Browse files Browse the repository at this point in the history
…ootless

[20.10 backport] docker-rootless-setuptools.sh fixes
  • Loading branch information
thaJeztah committed Sep 29, 2022
2 parents 4163c55 + c003392 commit f219cb5
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions contrib/dockerd-rootless-setuptool.sh
Expand Up @@ -353,19 +353,24 @@ install_nonsystemd() {

cli_ctx_exists() {
name="$1"
"${BIN}/docker" context inspect -f "{{.Name}}" "${name}" > /dev/null 2>&1
"${BIN}/docker" --context=default context inspect -f "{{.Name}}" "${name}" > /dev/null 2>&1
}

cli_ctx_create() {
name="$1"
host="$2"
description="$3"
"${BIN}/docker" context create "${name}" --docker "host=${host}" --description "${description}" > /dev/null
"${BIN}/docker" --context=default context create "${name}" --docker "host=${host}" --description "${description}" > /dev/null
}

cli_ctx_use() {
name="$1"
"${BIN}/docker" --context=default context use "${name}" > /dev/null
}

cli_ctx_rm() {
name="$1"
"${BIN}/docker" context rm -f "${name}" > /dev/null
"${BIN}/docker" --context=default context rm -f "${name}" > /dev/null
}

# CLI subcommand: "install"
Expand All @@ -384,6 +389,9 @@ cmd_entrypoint_install() {
cli_ctx_create "${CLI_CONTEXT}" "unix://${XDG_RUNTIME_DIR}/docker.sock" "Rootless mode"
fi

INFO "Use CLI context \"${CLI_CONTEXT}\""
cli_ctx_use "${CLI_CONTEXT}"

echo
INFO "Make sure the following environment variables are set (or add them to ~/.bashrc):"
echo
Expand All @@ -392,6 +400,7 @@ cmd_entrypoint_install() {
echo "export XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR}"
fi
echo "export PATH=${BIN}:\$PATH"
echo "Some applications may require the following environment variable too:"
echo "export DOCKER_HOST=unix://${XDG_RUNTIME_DIR}/docker.sock"
echo

Expand Down Expand Up @@ -420,7 +429,12 @@ cmd_entrypoint_uninstall() {
cli_ctx_rm "${CLI_CONTEXT}"
INFO "Deleted CLI context \"${CLI_CONTEXT}\""
fi

unset DOCKER_HOST
unset DOCKER_CONTEXT
cli_ctx_use "default"
INFO 'Configured CLI use the "default" context.'
INFO
INFO 'Make sure to unset or update the environment PATH, DOCKER_HOST, and DOCKER_CONTEXT environment variables if you have added them to `~/.bashrc`.'
INFO "This uninstallation tool does NOT remove Docker binaries and data."
INFO "To remove data, run: \`$BIN/rootlesskit rm -rf $HOME/.local/share/docker\`"
}
Expand Down

0 comments on commit f219cb5

Please sign in to comment.