Newer
Older
glx-docker-headless-gpu / Dockerfile
@ikko ikko on 1 Feb 2022 9 KB Update Dockerfile
FROM ubuntu:18.04

LABEL maintainer="ikko@hosei.ac.jp"

ARG CARLA_VERSION_FULL=0.9.13
ARG CARLA_VERSION=0.9.13
ENV NVIDIA_VISIBLE_DEVICES=all
ENV NVIDIA_DRIVER_CAPABILITIES=compute,graphics,display
ENV DEBIAN_FRONTEND noninteractive

# add new sudo user
ENV USERNAME kbkn
ENV USERPASS kobaken
ENV HOME /home/$USERNAME
RUN useradd -m $USERNAME && \
        echo "$USERNAME:$USERPASS" | 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 && \
        mkdir -p /home/$USERNAME/.cache  && \
        mkdir -p /home/$USERNAME/.config && \
        chown -Rf $USERNAME.$USERNAME /home/$USERNAME

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 python-pip \
        python-dev \
        python-protobuf \
        python-pexpect \
        pcl-tools \
        openssh-server \
        locales && \
    apt-get autoclean -y && apt-get autocremove -y  && rm -rf /var/lib/apt/lists/* && \
    locale-gen en_US.UTF-8

RUN pip install --upgrade pip setuptools 

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 && \
    apt-get autoclean -y && apt-get autocremove -y  && 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

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 && \
RUN  apt-get update && apt-get install -y --no-install-recommends \
        apt-utils \
        build-essential \
        ca-certificates \
        curl \
        wget \
        vim \
        zip \
        unzip \
        git \
        kmod \
        libc6 \
        pkg-config \
        libelf-dev \
        gnupg patch xinit && \
     apt-get autoclean -y && apt-get autocremove -y  && rm -rf /var/lib/apt/lists/* 

#        libc6:i386 \
# (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/*
# xserver-xorg-legacy && \
#RUN sed -i "s/allowed_users=console/allowed_users=anybody/;$ a needs_root_rights=yes" /etc/X11/Xwrapper.config

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 && \
    wget https://developer.download.nvidia.com/compute/cuda/11.6.0/local_installers/cuda-repo-ubuntu1804-11-6-local_11.6.0-510.39.01-1_amd64.deb && \
    dpkg -i cuda-repo-ubuntu1804-11-6-local_11.6.0-510.39.01-1_amd64.deb && \
    apt-key add /var/cuda-repo-ubuntu1804-11-6-local/7fa2af80.pub
RUN apt-get update && apt-get install -y --no-install-recommends \
    cuda-drivers && \
    apt-get autoclean -y && apt-get autocremove -y  && 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 lxterminal gnome-tweak-tool x11-apps \
    automake autoconf libssl-dev xorg-dev libvncserver-dev \
    xdg-user-dirs xdg-utils && \
    apt-get autoclean -y && apt-get autocremove -y  && rm -rf /var/lib/apt/lists/* && \
    git clone -b 0.9.16 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 \
    vulkan-utils firefox openbox menu alsa pulseaudio libgtk2.0-0 && \
    apt-get autoclean -y && apt-get autocremove -y  && rm -rf /var/lib/apt/lists/* 

# novnc
# download websockify as well
RUN wget https://github.com/novnc/noVNC/archive/v1.3.0.zip && \
    unzip -q v1.3.0.zip && \
    rm -rf v1.3.0.zip && \
    git clone -b v0.10.0 https://github.com/novnc/websockify /noVNC-1.3.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 && \ 
    apt-get autoclean -y && apt-get autocremove -y  && rm -rf /var/lib/apt/lists/* 

RUN echo "alias m='cd /home/$USERNAME ; su $USERNAME'" >> /home/$USERNAME/.bashrc 

# ROS Melodic
RUN sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
RUN apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
RUN apt-get update && apt-get install -y --no-install-recommends \
    ros-melodic-desktop-full \
    python-rosdep \
    python-rosinstall \
    python-rosinstall-generator \
    python-wstool && \
    apt-get autoclean -y && apt-get autocremove -y  && rm -rf /var/lib/apt/lists/* 

# addtional ROS package
RUN apt-get update && apt-get install -y --no-install-recommends \
    ros-melodic-derived-object-msgs \
    ros-melodic-ackermann-msgs \
    ros-melodic-ainstein-radar-msgs \
    python3-numpy \
    libomp-dev \
    libomp5 && \
    apt-get autoclean -y && apt-get autocremove -y  && rm -rf /var/lib/apt/lists/* 

RUN pip install --upgrade setuptools wheel && \
    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 \
        ephem \
        tabulate \
        networkx && \
      rosdep init

USER $USERNAME
WORKDIR /home/$USERNAME
RUN rosdep update
COPY CARLA_${CARLA_VERSION_FULL}.tar.gz /home/$USERNAME/
RUN mkdir CARLA_${CARLA_VERSION_FULL} && \
    tar xfvz CARLA_${CARLA_VERSION_FULL}.tar.gz -C CARLA_${CARLA_VERSION_FULL} && \
    rm /home/$USERNAME/CARLA_${CARLA_VERSION_FULL}.tar.gz

#COPY AdditionalMaps_${CARLA_VERSION_FULL}.tar.gz /home/$USERNAME/
#RUN tar xfvz AdditionalMaps_${CARLA_VERSION_FULL}.tar.gz -C /home/$USERNAME/CARLA_${CARLA_VERSION_FULL}/ && \
#    rm /home/$USERNAME/AdditionalMaps_${CARLA_VERSION_FULL}.tar.gz

RUN echo "export PYTHONPATH=$PYTHONPATH:~/CARLA_${CARLA_VERSION_FULL}/PythonAPI/carla/dist/carla-${CARLA_VERSION}-py2.7-linux-x86_64.egg:~/CARLA_${CARLA_VERSION_FULL}/PythonAPI/carla" >> ~/.bashrc

SHELL ["/bin/bash", "-c"]
RUN mkdir -p ~/catkin_ws/src && \
    source /opt/ros/melodic/setup.bash && \
    catkin_init_workspace ~/catkin_ws/src && \
    cd ~/catkin_ws/src && \
    git clone --recursive https://github.com/carla-simulator/ros-bridge.git -b 0.9.11 && \
    echo ${CARLA_VERSION} > /home/kbkn/catkin_ws/src/ros-bridge/carla_ros_bridge/src/carla_ros_bridge/CARLA_VERSION && \
    cd ~/catkin_ws && \
    catkin_make -DCMAKE_BUILD_TYPE=Release && \
    source ~/catkin_ws/devel/setup.bash

RUN cd /home/$USERNAME && \
    git clone https://github.com/carla-simulator/scenario_runner.git -b v${CARLA_VERSION}

RUN echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc && \
    echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc && \
    echo "alias cm='cd ~/catkin_ws;catkin_make'" >> ~/.bashrc && \
    echo "alias cs='cd ~/catkin_ws/src'" >> ~/.bashrc  && \
    echo "export SCENARIO_RUNNER_PATH=/home/$USERNAME/scenario_runner" >> ~/.bashrc && \
    pip install -r /home/kbkn/CARLA_${CARLA_VERSION}/PythonAPI/util/requirements.txt && \
    pip install -r /home/kbkn/CARLA_${CARLA_VERSION}/PythonAPI/carla/requirements.txt && \
    pip install -r /home/kbkn/scenario_runner/requirements.txt

USER root
WORKDIR /root
RUN echo "alias m='cd /home/$USERNAME ; su $USERNAME'" >> /root/.bashrc


COPY startup.sh /startup.sh
COPY scripts/ /home/$USERNAME/scripts/
EXPOSE 5900
EXPOSE 8081 

CMD ["bash", "/startup.sh"]