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.
This commit is contained in:
Stefan Becker 2023-03-27 16:30:34 +03:00 committed by GitHub
parent f2d385517c
commit cf40e4b299
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,10 +4,15 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
BUILD_OPTS="$*" BUILD_OPTS="$*"
DOCKER="docker" # Allow user to override docker command
DOCKER=${DOCKER:-docker}
if ! ${DOCKER} ps >/dev/null 2>&1; then # Ensure that default docker command is not set up in rootless mode
DOCKER="sudo docker" if \
! ${DOCKER} ps >/dev/null 2>&1 || \
${DOCKER} info 2>/dev/null | grep -q rootless \
; then
DOCKER="sudo ${DOCKER}"
fi fi
if ! ${DOCKER} ps >/dev/null; then if ! ${DOCKER} ps >/dev/null; then
echo "error connecting to docker:" echo "error connecting to docker:"