diff --git a/docker-cmd-mac.sh b/docker-cmd-mac.sh index b4815a5..9c2087a 100755 --- a/docker-cmd-mac.sh +++ b/docker-cmd-mac.sh @@ -23,6 +23,8 @@ EXEC=false CONTAINER="" DEVEL_DIR="" LEARN_DIR="" +USER_ID="" +GROUP_ID="" COMMAND="" EXP="" DETACH=false @@ -40,6 +42,8 @@ function print_help { echo " DETACH: ($DETACH) [--detach]" echo " DEVELOPMENT dir \"$DEVEL_DIR\" [-d, --devel]" echo " LEARNING dir \"$LEARN_DIR\" [-l, --learn]" + echo " USER ID \"$USER_ID\" [-u, --uid]" + echo " GROUP ID \"$GROUP_ID\" [-g, --gid]" } for arg in "$@" @@ -86,6 +90,12 @@ do -l=*|--learn=*) LEARN_DIR="${arg#*=}" ;; + -u=*|--uid=*) + USER_ID="${arg#*=}" + ;; + -g=*|--gid=*) + GROUP_ID="${arg#*=}" + ;; *) # unknown option echo "Unknown option \"$arg\"" @@ -105,14 +115,14 @@ if [[ "$BUILD" = true ]]; then if [[ "$CACHE" = true ]]; then echo "Building the docker container using the cache, if present." docker build \ - --build-arg USER_ID=$(id -u ${USER}) \ - --build-arg GROUP_ID=$(id -g ${USER}) \ + --build-arg USER_ID="$USER_ID" \ + --build-arg GROUP_ID="$GROUP_ID" \ -t "$IMAGE_NAME" "$IMAGE_FOLDER" else echo "Building the docker container ignoring the cache, even if present." docker build \ - --build-arg USER_ID=$(id -u ${USER}) \ - --build-arg GROUP_ID=$(id -g ${USER}) \ + --build-arg USER_ID="$USER_ID" \ + --build-arg GROUP_ID="$GROUP_ID" \ --no-cache -t "$IMAGE_NAME" "$IMAGE_FOLDER" fi fi diff --git a/docker-image-mac/Dockerfile b/docker-image-mac/Dockerfile index 4e3e2d5..3e9d83a 100644 --- a/docker-image-mac/Dockerfile +++ b/docker-image-mac/Dockerfile @@ -69,8 +69,8 @@ RUN python -m pip install ray[rllib] RUN python -m pip install ray[tune] # Working user -RUN groupadd --gid 222 alice && \ - useradd -m -s /bin/bash -u 502 -g 222 alice && \ +RUN groupadd --gid ${GROUP_ID} alice && \ + useradd -m -s /bin/bash -u ${USER_ID} -g ${GROUP_ID} alice && \ echo "alice:alice" | chpasswd && adduser alice sudo USER alice diff --git a/docs/howto-mac.md b/docs/howto-mac.md index 1d5188e..99be8ac 100644 --- a/docs/howto-mac.md +++ b/docs/howto-mac.md @@ -4,11 +4,12 @@ Basic command to use: -`bash docker-cmd-mac.sh --build` +`bash docker-cmd-mac.sh --build --uid=502 --gid=222` - The default tag name of this image is `tf-gpu-sumo-{today_date}`. You can also add option such as `--image-name={new_name}` to specify your own name; - The default path of the dockerfile to be used is `docker-image-mac`. You can adapt to your setting by using option `--image-folder`; - The default image building process does not use cache. You can enable it by adding the option `--cache`. +- The user id and group id are suggested as 502 and 222 respectively. The range of valid values on MacOS needs to be further studied. ## Step 2: Run a container of the built image @@ -46,6 +47,8 @@ Default parameters: DETACH: (true) [--detach] DEVELOPMENT dir "" [-d, --devel] LEARNING dir "" [-l, --learn] + USER_ID "" [-u, --uid] + GROUP_ID "" [-g, --gid] ``` Example of use: