Skip to content

Commit 8dac40a

Browse files
committed
Fix BASE_FOLDER issue when evaluating script on different path
1 parent 217db02 commit 8dac40a

4 files changed

Lines changed: 8 additions & 6 deletions

File tree

.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ TIME_ZONE=${TIME_ZONE:-UTC}
1414
CONTAINER_NAME=${IMAGE_NAME}
1515
HOME_FOLDER=/home/${IMAGE_USER}
1616
CODE_FOLDER=${IMAGE_NAME}
17-
BASE_FOLDER=$(pwd)
1817

1918
HOST_UID=$(id -u)
2019
HOST_GID=$(id -g)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Continue on a machine where you have docker permission, HPC clusters usually res
2727

2828
1. Modify `todo-docker-user`, `todo-base-image`, `todo-image-name`, `todo-image-user` in [.env](.env)
2929

30-
- [.env](env) will be loaded when you use docker compose for build/run/push
30+
- [.env](.env) will be loaded when you use docker compose for build/run/push
3131
- `todo-docker-user` refers to your docker hub account username
3232
- `todo-base-image` is the image dockerfile is based on, such as `nvidia/cuda:13.0.0-cudnn-devel-ubuntu24.04`
3333
- `todo-image-user` refers to the default user inside the image, which is used to determine home folder
@@ -47,7 +47,7 @@ Continue on a machine where you have docker permission, HPC clusters usually res
4747
1. [run_docker_container.sh](scripts/run_docker_container.sh) or `docker compose up -d` to run and test a built image
4848

4949
- The service by default will mount the whole repository onto `CODE_FOLDER` inside the container so any modification inside also takes effect outside, which is useful when you use vscode remote extension to develop inside a running container with remote docker context
50-
- You should be able to run and see GUI applications inside the container if `$DISPLAY` is set correctly when you run the script
50+
- You should be able to run and see GUI applications inside the container if `DISPLAY` is set correctly when you run the script
5151

5252
1. [push_docker_image.sh](scripts/push_docker_image.sh) to push the multi-arch image to docker hub
5353

scripts/run_docker_container.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ xhost +local:*
1414

1515
if [ ! -f "${XAUTH}" ]; then
1616
touch "${XAUTH}"
17-
xauth_list=$(xauth nlist "$DISPLAY" | sed -e 's/^..../ffff/')
17+
xauth_list=$(xauth nlist "${DISPLAY}" | sed -e 's/^..../ffff/')
1818
if [ -n "${xauth_list}" ]; then
1919
echo "${xauth_list}" | xauth -f "${XAUTH}" nmerge -
2020
fi
@@ -31,15 +31,16 @@ docker run \
3131
--name "${CONTAINER_NAME}" \
3232
--hostname "$(hostname)" \
3333
--privileged \
34-
--cpus "$AVAILABLE_CORES" \
34+
--cpus "${AVAILABLE_CORES}" \
35+
--user root \
3536
--network host \
3637
--ipc host \
3738
--pid host \
3839
--ulimit core=-1 \
3940
--group-add audio \
4041
--group-add video \
4142
--volume=":" \
42-
-e DISPLAY="$DISPLAY" \
43+
-e DISPLAY="${DISPLAY}" \
4344
-e XAUTHORITY="${XAUTH}" \
4445
-e QT_X11_NO_MITSHM=1 \
4546
-v /var/lib/systemd/coredump/:/cores \

scripts/variables.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@ set +a
3838
# export additional derived variables below if needed, e.g. resolved absolute paths
3939
# SOME_PATH="$(resolve_host_path "${SOME_PATH:-}")"
4040
# export SOME_PATH
41+
BASE_FOLDER="$(resolve_host_path "$(dirname "$0")"/..)"
42+
export BASE_FOLDER

0 commit comments

Comments
 (0)