Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
de-hardcoded uid and gid settings
Browse files Browse the repository at this point in the history
  • Loading branch information
swangcs committed Aug 10, 2020
1 parent ad4dbca commit ac6dd1c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
18 changes: 14 additions & 4 deletions docker-cmd-mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ EXEC=false
CONTAINER=""
DEVEL_DIR=""
LEARN_DIR=""
USER_ID=""
GROUP_ID=""
COMMAND=""
EXP=""
DETACH=false
Expand All @@ -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 "$@"
Expand Down Expand Up @@ -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\""
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docker-image-mac/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion docs/howto-mac.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit ac6dd1c

Please sign in to comment.