I want to use docker with VSCode. However, because I need to use GUI interface, I need to connect the run some script before the running the container. My script looks like this:
# For Display, Connect to XServer
XAUTH=/tmp/.docker.xauth
if [ ! -f $XAUTH ]; then
xauth_list=$(xauth nlist $DISPLAY)
xauth_list=$(sed -e 's/^..../ffff/' <<<"$xauth_list")
if [ ! -z "$xauth_list" ]; then
echo "$xauth_list" | xauth -f $XAUTH nmerge -
else
touch $XAUTH
fi
chmod a+r $XAUTH
fi
# Prevent executing "docker run" when xauth failed.
if [ ! -f $XAUTH ]; then
echo "[$XAUTH] was not properly created. Exiting..."
exit 1
fi
docker run
-it
--rm
-v $REPO_DIRECTORY:/root/$REPO_NAME
--network host
--gpus all
--runtime=nvidia
--env="DISPLAY"
--env="QT_X11_NO_MITSHM=1"
--env="XAUTHORITY=$XAUTH"
--volume="$XAUTH:$XAUTH"
$REPO_NAME:latest
bash
I am not sure how to convert the above process into devcontainer.json
. It seems like all the command runs after the container starts.
Thank you!