From 7bf1b5500176ae1400d557380a9df61f7367bbca Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Mon, 5 Jul 2021 09:42:38 -0700 Subject: [PATCH] Add a --root option to run_docker to run container as root (#1686) --- run_docker | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/run_docker b/run_docker index 5d16eacf0..698c7829d 100755 --- a/run_docker +++ b/run_docker @@ -8,6 +8,17 @@ DEFAULT_PYODIDE_SYSTEM_PORT="8000" DOCKER_COMMAND="/bin/bash" DOCKER_INTERACTIVE="--interactive" + +USER_HOME="/src/.docker_home" +USER_NAME="$(id -u -n)" +USER_PASS="x" +USER_ID="$(id -u)" +USER_GID=0 +USER_COMMENT_FIELD="${USER_NAME} pyodide user alias" +USER_INTERPRETER="/sbin/nologin" +USER_ACCOUNT_INFO="${USER_NAME}:${USER_PASS}:${USER_ID}:${USER_GID}:${USER_COMMENT_FIELD}:${USER_HOME}:${USER_INTERPRETER}" +USER_FLAG="--user $(id --user):$(id --group)" + set -eo pipefail @@ -27,6 +38,7 @@ Options: If set to 'none', docker instance will not bind to any port. --non-interactive Run docker without the --interactive flag. Useful for running in headless mode on CI server. + --root Run as root user inside the container Prerequisites: Docker has to be set up on your system. @@ -69,6 +81,10 @@ do DOCKER_INTERACTIVE="--interactive=false" shift ;; + --root) + USER_FLAG="" + shift + ;; -*) >&2 echo "Unknown option $1" error @@ -100,15 +116,6 @@ esac mkdir -p .docker_home -USER_HOME="/src/.docker_home" -USER_NAME="$(id -u -n)" -USER_PASS="x" -USER_ID="$(id -u)" -USER_GID=0 -USER_COMMENT_FIELD="${USER_NAME} pyodide user alias" -USER_INTERPRETER="/sbin/nologin" -USER_ACCOUNT_INFO="${USER_NAME}:${USER_PASS}:${USER_ID}:${USER_GID}:${USER_COMMENT_FIELD}:${USER_HOME}:${USER_INTERPRETER}" - # Start a detached container as root, add the host uname and uid to /etc/passwd, # then run forever CONTAINER=$(\ @@ -128,7 +135,7 @@ EXIT_STATUS=0 # Execute the provided command as the host user with HOME=/src docker exec \ $DOCKER_INTERACTIVE --tty \ - --user $(id --user):$(id --group) \ + $USER_FLAG \ $CONTAINER \ /bin/bash -c "${DOCKER_COMMAND}" || EXIT_STATUS=$?