From f6e2ea7b96835954271f74bd857d8ade05a3f603 Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Sun, 19 Oct 2025 01:01:10 +0900 Subject: [PATCH] build/common.sh: fix support for Rootless Docker In the case of Rootless mode, `docker run` should not be invoked with `--user`. Fix issue 134669 Regression in PR 134510 Signed-off-by: Akihiro Suda --- build/common.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/build/common.sh b/build/common.sh index d9c0a30d128..717ca5777b8 100755 --- a/build/common.sh +++ b/build/common.sh @@ -322,6 +322,10 @@ function kube::build::destroy_container() { "${DOCKER[@]}" rm -f -v "$1" >/dev/null 2>&1 || true } +function kube::build::is_docker_rootless() { + "${DOCKER[@]}" info --format '{{json .SecurityOptions}}' | grep -q "name=rootless" +} + # --------------------------------------------------------------------------- # Building @@ -367,11 +371,12 @@ function kube::build::run_build_command_ex() { local -a docker_run_opts=( "--name=${container_name}" - "--user=$(id -u):$(id -g)" "--hostname=${HOSTNAME}" "-e=GOPROXY=${GOPROXY}" ) + kube::build::is_docker_rootless || docker_run_opts+=("--user=$(id -u):$(id -g)") + local detach=false [[ $# != 0 ]] || { echo "Invalid input - please specify docker arguments followed by --." >&2; return 4; }