Last active
August 28, 2022 13:13
-
-
Save jackersson/6861fea6ae3d219cf843bb8fe314bd52 to your computer and use it in GitHub Desktop.
AirSim Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ARG BASE_IMAGE=nvidia/cudagl:10.0-devel-ubuntu18.04 | |
FROM $BASE_IMAGE | |
# NVIDIA packages workaround. | |
# Reason: https://forums.developer.nvidia.com/t/notice-cuda-linux-repository-key-rotation/212772 | |
COPY cuda-keyring_1.0-1_all.deb . | |
RUN apt-key del 7fa2af80 | |
RUN rm /etc/apt/sources.list.d/cuda.list && rm /etc/apt/sources.list.d/nvidia-ml.list | |
RUN dpkg -i cuda-keyring_1.0-1_all.deb | |
RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y --no-install-recommends \ | |
python3 \ | |
python3-pip \ | |
sudo \ | |
libglu1-mesa-dev \ | |
xdg-user-dirs \ | |
pulseaudio \ | |
x11-xserver-utils | |
RUN packages='libsdl2-2.0-0 libsdl2-dev xserver-xorg libvulkan1 libvulkan-dev' \ | |
&& apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y $packages --no-install-recommends \ | |
&& VULKAN_API_VERSION=`dpkg -s libvulkan1 | grep -oP 'Version: [0-9|\.]+' | grep -oP '[0-9|\.]+'` && \ | |
mkdir -p /etc/vulkan/icd.d/ && \ | |
echo \ | |
"{\ | |
\"file_format_version\" : \"1.0.0\",\ | |
\"ICD\": {\ | |
\"library_path\": \"libGLX_nvidia.so.0\",\ | |
\"api_version\" : \"${VULKAN_API_VERSION}\"\ | |
}\ | |
}" > /etc/vulkan/icd.d/nvidia_icd.json \ | |
&& rm -rf /var/lib/apt/lists/* | |
RUN python3 -m pip install --upgrade wheel pip setuptools && \ | |
pip3 install numpy msgpack-rpc-python && \ | |
pip3 install airsim | |
RUN adduser --force-badname --disabled-password --gecos '' --shell /bin/bash airsim_user && \ | |
echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers && \ | |
adduser airsim_user sudo && \ | |
adduser airsim_user audio && \ | |
adduser airsim_user video | |
USER airsim_user | |
WORKDIR /home/airsim_user | |
RUN mkdir -p /home/airsim_user/Documents/AirSim | |
COPY settings.json /home/airsim_user/Documents/AirSim | |
#ADD Documents /home/airsim_user/Documents | |
RUN sudo chown -R airsim_user /home/airsim_user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DOCKER_IMAGE_NAME=$1 | |
# get the base directory name of the unreal binary's shell script | |
# we'll mount this volume while running docker container | |
UNREAL_BINARY_PATH=$(dirname $(readlink -f $2)) | |
UNREAL_BINARY_SHELL_ABSPATH=$(readlink -f $2) | |
# This is to determine Docker version for the command | |
version_less_than_equal_to() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" = "$1"; } | |
REQ_DOCKER_VERSION=19.03 | |
docker_version=$(docker -v | cut -d ' ' -f3 | sed 's/,$//') | |
if version_less_than_equal_to $REQ_DOCKER_VERSION $docker_version; then | |
# Use the normal docker command | |
DOCKER_CMD="docker run" | |
else | |
# Use nvidia-docker | |
DOCKER_CMD="nvidia-docker run --runtime=nvidia" | |
fi | |
# this block is for running X apps in docker | |
XAUTH=/tmp/.docker.xauth | |
if [ ! -f $XAUTH ] | |
then | |
xauth_list=$(xauth nlist :0 | sed -e 's/^..../ffff/') | |
if [ ! -z "$xauth_list" ] | |
then | |
echo $xauth_list | xauth -f $XAUTH nmerge - | |
else | |
touch $XAUTH | |
fi | |
chmod a+r $XAUTH | |
fi | |
# this are the first (maximum) four arguments which the user specifies: | |
# ex: ./run_airsim_image.sh /PATH/TO/UnrealBinary/UnrealBinary.sh -windowed -ResX=1080 -ResY=720 | |
# we save them in a variable right now: | |
UNREAL_BINARY_COMMAND="$UNREAL_BINARY_SHELL_ABSPATH $3 $4 $5" | |
# now let's check if user specified an "-- headless" parameter in the end | |
# we'll set SDL_VIDEODRIVER_VALUE to '' if it wasn't specified, 'offscreen' if it was | |
SDL_VIDEODRIVER_VALUE=''; | |
while [ -n "$1" ]; do | |
case "$1" in | |
--) | |
shift | |
break | |
;; | |
esac | |
shift | |
done | |
for param in $@; do | |
case "$param" in | |
headless) SDL_VIDEODRIVER_VALUE='offscreen' ;; | |
esac | |
done | |
# now, let's mount the user directory which points to the unreal binary (UNREAL_BINARY_PATH) | |
# set the environment varible SDL_VIDEODRIVER to SDL_VIDEODRIVER_VALUE | |
# and tell the docker container to execute UNREAL_BINARY_COMMAND | |
$DOCKER_CMD -it \ | |
-v $(pwd)/settings.json:/home/airsim_user/Documents/AirSim/settings.json \ | |
-v $UNREAL_BINARY_PATH:$UNREAL_BINARY_PATH \ | |
-e SDL_VIDEODRIVER=$SDL_VIDEODRIVER_VALUE \ | |
-e SDL_HINT_CUDA_DEVICE='0' \ | |
--net=host \ | |
--env="DISPLAY=$DISPLAY" \ | |
--env="QT_X11_NO_MITSHM=1" \ | |
--volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \ | |
-env="XAUTHORITY=$XAUTH" \ | |
--volume="$XAUTH:$XAUTH" \ | |
--runtime=nvidia \ | |
--device /dev/dri \ | |
--gpus 'all,"capabilities=compute,utility,graphics,display"' \ | |
--rm \ | |
$DOCKER_IMAGE_NAME \ | |
/bin/bash -c "$UNREAL_BINARY_COMMAND" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment