summaryrefslogtreecommitdiff
path: root/build-docker.sh
diff options
context:
space:
mode:
authorStefan Becker <stefanb2@users.noreply.github.com>2023-03-27 16:30:34 +0300
committerGitHub <noreply@github.com>2023-03-27 14:30:34 +0100
commitcf40e4b299ca4023f842eed1ecc5b254eb3eb688 (patch)
treefefdc8f3cab30adf30903946d162b55b0ac13e29 /build-docker.sh
parentf2d385517c9631f2ded876deb1115725d0c75995 (diff)
Check that docker is not set up in rootless mode (#679)
Mounting binfmt_misc inside the container requires root rights. If "docker info" indicates rootless mode then fall back to "sudo docker". Allow the user to override the docker command with the DOCKER by setting the environment variable.
Diffstat (limited to 'build-docker.sh')
-rwxr-xr-xbuild-docker.sh13
1 files changed, 9 insertions, 4 deletions
diff --git a/build-docker.sh b/build-docker.sh
index a7f18f1..b3995d5 100755
--- a/build-docker.sh
+++ b/build-docker.sh
@@ -4,10 +4,15 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
BUILD_OPTS="$*"
-DOCKER="docker"
-
-if ! ${DOCKER} ps >/dev/null 2>&1; then
- DOCKER="sudo docker"
+# Allow user to override docker command
+DOCKER=${DOCKER:-docker}
+
+# Ensure that default docker command is not set up in rootless mode
+if \
+ ! ${DOCKER} ps >/dev/null 2>&1 || \
+ ${DOCKER} info 2>/dev/null | grep -q rootless \
+; then
+ DOCKER="sudo ${DOCKER}"
fi
if ! ${DOCKER} ps >/dev/null; then
echo "error connecting to docker:"