Newer
Older
glx-docker-headless-gpu / Dockerfile
#FROM ubuntu:18.04
FROM nvidia/vulkan:1.1.121-cuda-10.1--ubuntu18.04

# Make all NVIDIA GPUS visible, but I want to manually install drivers
ARG NVIDIA_VISIBLE_DEVICES=all
# Supress interactive menu while installing keyboard-configuration
ARG DEBIAN_FRONTEND=noninteractive

RUN sed -i 's#http://archive.ubuntu.com/ubuntu/#mirror://mirrors.ubuntu.com/mirrors.txt#' /etc/apt/sources.list;

# add new sudo user
ENV USERNAME kbkn
ENV HOME /home/$USERNAME
RUN useradd -m $USERNAME && \
        echo "$USERNAME:$USERNAME" | chpasswd && \
        usermod --shell /bin/bash $USERNAME && \
        usermod -aG sudo $USERNAME && \
        mkdir /etc/sudoers.d && \
        echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/$USERNAME && \
        chmod 0440 /etc/sudoers.d/$USERNAME && \
        # Replace 1000 with your user/group id
        usermod  --uid 1000 $USERNAME && \
        groupmod --gid 1000 $USERNAME && \
        chown -Rf $USERNAME.$USERNAME /home/$USERNAME && \
        mkdir -p /home/$USERNAME/.cache  && \
        chmod -R 777 /home/$USERNAME/.cache 

RUN apt-get update && apt-get install -y --no-install-recommends \
        sudo \
        less \
        tmux \
        bash-completion \
        command-not-found \
        software-properties-common \
        xsel \
        xdg-user-dirs \
        python-pip \
        python-protobuf \
        python-pexpect \
        pcl-tools \
        openssh-server \
        && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*
RUN packages='libsdl2-2.0 xserver-xorg libvulkan1' \
	&& 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/*

# Error constructing proxy for org.gnome.Terminal:/org/gnome/Terminal/Factory0: Failed to execute child process dbus-launch (No such file or directory)
# fix by setting LANG https://askubuntu.com/questions/608330/problem-with-gnome-terminal-on-gnome-3-12-2
# to install locales https://stackoverflow.com/questions/39760663/docker-ubuntu-bin-sh-1-locale-gen-not-found
RUN apt-get clean && \
    apt-get update && \
    apt-get install -y locales && \
    rm -rf /var/lib/apt/lists/* && \
    locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

# (1) Install Xorg and NVIDIA driver inside the container
# Almost same procesure as nvidia/driver https://gitlab.com/nvidia/driver/blob/master/ubuntu16.04/Dockerfile

# (1-1) Install prerequisites
RUN dpkg --add-architecture i386 && \
    apt-get update && apt-get install -y --no-install-recommends \
        apt-utils \
        build-essential \
        ca-certificates \
        curl \
        wget \
        vim \
        zip \
        unzip \
        git \
        python \
        kmod \
        libc6:i386 \
        pkg-config \
        libelf-dev && \
    rm -rf /var/lib/apt/lists/*

# (1-2) Install xorg server and xinit BEFORE INSTALLING NVIDIA DRIVER.
# After this installation, command Xorg and xinit can be used in the container
# if you need full ubuntu desktop environment, the line below should be added.
        # ubuntu-desktop \
RUN apt-get update && apt-get install -y \
        xinit && \
    rm -rf /var/lib/apt/lists/*

# (1-3) Install NVIDIA drivers, including X graphic drivers
# Same command as nvidia/driver, except --x-{prefix,module-path,library-path,sysconfig-path} are omitted in order to make use default path and enable X drivers.
# Driver version must be equal to host's driver
# Install the userspace components and copy the kernel module sources.
#ENV DRIVER_VERSION=410.129-diagnostic
#ENV DRIVER_VERSION_PATH=410.129
#RUN cd /tmp && \
#    curl -fSsl -O https://us.download.nvidia.com/tesla/$DRIVER_VERSION_PATH/NVIDIA-Linux-x86_64-$DRIVER_VERSION.run && \
#    sh NVIDIA-Linux-x86_64-$DRIVER_VERSION.run -x && \
#    cd NVIDIA-Linux-x86_64-$DRIVER_VERSION && \
#    ./nvidia-installer --silent \
#                       --no-kernel-module \
#                       --install-compat32-libs \
#                       --no-nouveau-check \
#                       --no-nvidia-modprobe \
#                       --no-rpms \
#                       --no-backup \
#                       --no-check-for-alternate-installs \
#                       --no-libglx-indirect \
#                       --no-glvnd-egl-client \
#                      --no-glvnd-glx-client \
#                       --no-install-libglvnd && \
#    mkdir -p /usr/src/nvidia-$DRIVER_VERSION && \
#    mv LICENSE mkprecompiled kernel /usr/src/nvidia-$DRIVER_VERSION && \
#    sed '9,${/^\(kernel\|LICENSE\)/!d}' .manifest > /usr/src/nvidia-$DRIVER_VERSION/.manifest
                       # this option cannot be used on newer driver
                       # --no-glvnd-egl-client \
                       # --no-glvnd-glx-client \
COPY cuda-repo-ubuntu1804-11-2-local_11.2.2-460.32.03-1_amd64.deb /tmp/cuda-repo-ubuntu1804-11-2-local_11.2.2-460.32.03-1_amd64.deb
RUN cd /tmp && \
    wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin && \
    mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600 && \
    dpkg -i cuda-repo-ubuntu1804-11-2-local_11.2.2-460.32.03-1_amd64.deb && \
    apt-key add /var/cuda-repo-ubuntu1804-11-2-local/7fa2af80.pub && \
    apt-get update && apt-get install -y --no-install-recommends \
    cuda-drivers && \
    rm -rf cuda-repo-ubuntu1804-11-2-local_11.2.2-460.32.03-1_amd64.deb && \
    rm -rf /var/lib/apt/lists/*


# (2) Configurate Xorg
# (2-1) Install some necessary softwares
#
# pkg-config: nvidia-xconfig requires this package
# mesa-utils: This package includes glxgears and glxinfo, which is useful for testing GLX drivers
# x11vnc: Make connection between x11 server and VNC client.
# x11-apps: xeyes can be used to make sure that X11 server is running.
#
# Note: x11vnc in ubuntu18.04 is useless beacuse of stack smashing bug. See below to manual compilation.
RUN apt-get update && apt-get install -y --no-install-recommends \
        mesa-utils \
        x11-apps && \
    rm -rf /var/lib/apt/lists/*

# solution for the `stack smashing detected` issue
# https://github.com/LibVNC/x11vnc/issues/61
RUN apt-get update && apt-get install -y --no-install-recommends \
        automake autoconf libssl-dev xorg-dev libvncserver-dev xdg-user-dirs xdg-utils && \
    rm -rf /var/lib/apt/lists/* && \
    git clone https://github.com/LibVNC/x11vnc.git && \
    cd x11vnc && \
    ./autogen.sh && \
    make && \
    cp src/x11vnc /usr/bin/x11vnc

# (2-2) Optional vulkan support
# vulkan-utils includes vulkan-smoketest, benchmark software of vulkan API
RUN apt-get update && apt-get install -y --no-install-recommends \
        libvulkan1 vulkan-utils && \
    rm -rf /var/lib/apt/lists/*

# for test
RUN apt-get update && apt-get install -y --no-install-recommends \
        firefox openbox menu && \
    rm -rf /var/lib/apt/lists/*

# sound driver and GTK library
# If you want to use sounds on docker, try `pulseaudio --start`
RUN apt-get update && apt-get install -y --no-install-recommends \
      alsa pulseaudio libgtk2.0-0 && \
    rm -rf /var/lib/apt/lists/*

# novnc
# download websockify as well
RUN wget https://github.com/novnc/noVNC/archive/v1.1.0.zip && \
  unzip -q v1.1.0.zip && \
  rm -rf v1.1.0.zip && \
  git clone https://github.com/novnc/websockify /noVNC-1.1.0/utils/websockify

# Xorg segfault error
# dbus-core: error connecting to system bus: org.freedesktop.DBus.Error.FileNotFound (Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory)
# related? https://github.com/Microsoft/WSL/issues/2016
RUN apt-get update && apt-get install -y --no-install-recommends \
      dbus-x11 \
      libdbus-c++-1-0v5 \
      software-properties-common && \
    rm -rf /var/lib/apt/lists/*

# (3) Run Xorg server + x11vnc + X applications
# see run.sh for details
RUN echo "alias m='cd /home/$USERNAME ; su $USERNAME'" >> /home/kbkn/.bashrc && \
    apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 1AF1527DE64CB8D9 && \
    add-apt-repository "deb [arch=amd64] http://dist.carla.org/carla $(lsb_release -sc) main" && \
    mkdir -p /opt/carla-simulator && \
    cd /opt/carla-simulator && \
    apt-get update && apt-get install -y --no-install-recommends \
    carla-simulator=0.9.10-1 \
    libxerces-c-dev python-dev python3-dev iproute2 && \
    rm -rf /var/lib/apt/lists/* && \
    echo "export PYTHONPATH=$PYTHONPATH:/opt/carla-simulator/PythonAPI/carla/dist/carla-0.9.10-py2.7-linux-x86_64.egg:/opt/carla-simulation/PythonAPI/carla" >> ~/.bashrc && \
    pip install --upgrade setuptools && \
    pip install \
        simple-pid \
        numpy \
        pygame \
        transforms3d \
        future \
        matplotlib \
        open3d \
        pyrsistent==0.16.1 \
        psutil \
        py-cpuinfo \
        python-tr \
        xmlschema==1.0.18 \
        py-trees==0.8.3 \
        Shapely \
        mkdocs \
        markdown-include \
        mkdocs-redirects \
        networkx

COPY AdditionalMaps_0.9.10.1.tar.gz /home/$USERNAME/
RUN tar xfvz /home/$USERNAME/AdditionalMaps_0.9.10.1.tar.gz -C /opt/carla-simulator/ && \
    rm /home/$USERNAME/AdditionalMaps_0.9.10.1.tar.gz && \
    mkdir -p /home/$USERNAME/.config && \
    chmod -R 777 /home/$USERNAME/.config
 
 
COPY run.sh /run.sh
CMD ["bash", "/run.sh"]