Newer
Older
glx-docker-headless-gpu / Dockerfile
@ikko ikko on 1 Feb 2022 9 KB Update Dockerfile
  1. FROM ubuntu:18.04
  2.  
  3. LABEL maintainer="ikko@hosei.ac.jp"
  4.  
  5. ARG CARLA_VERSION_FULL=0.9.13
  6. ARG CARLA_VERSION=0.9.13
  7. ENV NVIDIA_VISIBLE_DEVICES=all
  8. ENV NVIDIA_DRIVER_CAPABILITIES=compute,graphics,display
  9. ENV DEBIAN_FRONTEND noninteractive
  10.  
  11. # add new sudo user
  12. ENV USERNAME kbkn
  13. ENV USERPASS kobaken
  14. ENV HOME /home/$USERNAME
  15. RUN useradd -m $USERNAME && \
  16. echo "$USERNAME:$USERPASS" | chpasswd && \
  17. usermod --shell /bin/bash $USERNAME && \
  18. usermod -aG sudo $USERNAME && \
  19. mkdir /etc/sudoers.d && \
  20. echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/$USERNAME && \
  21. chmod 0440 /etc/sudoers.d/$USERNAME && \
  22. # Replace 1000 with your user/group id
  23. usermod --uid 1000 $USERNAME && \
  24. groupmod --gid 1000 $USERNAME && \
  25. mkdir -p /home/$USERNAME/.cache && \
  26. mkdir -p /home/$USERNAME/.config && \
  27. chown -Rf $USERNAME.$USERNAME /home/$USERNAME
  28.  
  29. RUN apt-get update && apt-get install -y --no-install-recommends \
  30. sudo less tmux \
  31. bash-completion \
  32. command-not-found \
  33. software-properties-common \
  34. xsel xdg-user-dirs \
  35. python python-pip \
  36. python-dev \
  37. python-protobuf \
  38. python-pexpect \
  39. pcl-tools \
  40. openssh-server \
  41. locales && \
  42. apt-get autoclean -y && apt-get autocremove -y && rm -rf /var/lib/apt/lists/* && \
  43. locale-gen en_US.UTF-8
  44.  
  45. RUN pip install --upgrade pip setuptools
  46.  
  47. RUN packages='libsdl2-2.0 xserver-xorg libvulkan1' && \
  48. apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y $packages --no-install-recommends && \
  49. VULKAN_API_VERSION=`dpkg -s libvulkan1 | grep -oP 'Version: [0-9|\.]+' | grep -oP '[0-9|\.]+'` && \
  50. mkdir -p /etc/vulkan/icd.d/ && \
  51. echo \
  52. "{\
  53. \"file_format_version\" : \"1.0.0\",\
  54. \"ICD\": {\
  55. \"library_path\": \"libGLX_nvidia.so.0\",\
  56. \"api_version\" : \"${VULKAN_API_VERSION}\"\
  57. }\
  58. }" > /etc/vulkan/icd.d/nvidia_icd.json && \
  59. apt-get autoclean -y && apt-get autocremove -y && rm -rf /var/lib/apt/lists/*
  60.  
  61. # Error constructing proxy for org.gnome.Terminal:/org/gnome/Terminal/Factory0: Failed to execute child process dbus-launch (No such file or directory)
  62. # fix by setting LANG https://askubuntu.com/questions/608330/problem-with-gnome-terminal-on-gnome-3-12-2
  63. # to install locales https://stackoverflow.com/questions/39760663/docker-ubuntu-bin-sh-1-locale-gen-not-found
  64.  
  65. ENV LANG en_US.UTF-8
  66. ENV LANGUAGE en_US:en
  67. ENV LC_ALL en_US.UTF-8
  68.  
  69. # (1) Install Xorg and NVIDIA driver inside the container
  70. # Almost same procesure as nvidia/driver https://gitlab.com/nvidia/driver/blob/master/ubuntu16.04/Dockerfile
  71.  
  72. # (1-1) Install prerequisites
  73. #RUN dpkg --add-architecture i386 && \
  74. RUN apt-get update && apt-get install -y --no-install-recommends \
  75. apt-utils \
  76. build-essential \
  77. ca-certificates \
  78. curl \
  79. wget \
  80. vim \
  81. zip \
  82. unzip \
  83. git \
  84. kmod \
  85. libc6 \
  86. pkg-config \
  87. libelf-dev \
  88. gnupg patch xinit && \
  89. apt-get autoclean -y && apt-get autocremove -y && rm -rf /var/lib/apt/lists/*
  90.  
  91. # libc6:i386 \
  92. # (1-2) Install xorg server and xinit BEFORE INSTALLING NVIDIA DRIVER.
  93. # After this installation, command Xorg and xinit can be used in the container
  94. # if you need full ubuntu desktop environment, the line below should be added.
  95. # ubuntu-desktop \
  96. #RUN apt-get update && apt-get install -y xinit && \
  97. # rm -rf /var/lib/apt/lists/*
  98. # xserver-xorg-legacy && \
  99. #RUN sed -i "s/allowed_users=console/allowed_users=anybody/;$ a needs_root_rights=yes" /etc/X11/Xwrapper.config
  100.  
  101. RUN cd /tmp && \
  102. wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin && \
  103. mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600 && \
  104. 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 && \
  105. dpkg -i cuda-repo-ubuntu1804-11-6-local_11.6.0-510.39.01-1_amd64.deb && \
  106. apt-key add /var/cuda-repo-ubuntu1804-11-6-local/7fa2af80.pub
  107. RUN apt-get update && apt-get install -y --no-install-recommends \
  108. cuda-drivers && \
  109. apt-get autoclean -y && apt-get autocremove -y && rm -rf /var/lib/apt/lists/*
  110.  
  111.  
  112. # (2) Configurate Xorg
  113. # (2-1) Install some necessary softwares
  114. #
  115. # pkg-config: nvidia-xconfig requires this package
  116. # mesa-utils: This package includes glxgears and glxinfo, which is useful for testing GLX drivers
  117. # x11vnc: Make connection between x11 server and VNC client.
  118. # x11-apps: xeyes can be used to make sure that X11 server is running.
  119. #
  120. # Note: x11vnc in ubuntu18.04 is useless beacuse of stack smashing bug. See below to manual compilation.
  121.  
  122. RUN apt-get update && apt-get install -y --no-install-recommends \
  123. mesa-utils lxterminal gnome-tweak-tool x11-apps \
  124. automake autoconf libssl-dev xorg-dev libvncserver-dev \
  125. xdg-user-dirs xdg-utils && \
  126. apt-get autoclean -y && apt-get autocremove -y && rm -rf /var/lib/apt/lists/* && \
  127. git clone -b 0.9.16 https://github.com/LibVNC/x11vnc.git && \
  128. cd x11vnc && \
  129. ./autogen.sh && \
  130. make && \
  131. cp src/x11vnc /usr/bin/x11vnc
  132.  
  133. # (2-2) Optional vulkan support
  134. # vulkan-utils includes vulkan-smoketest, benchmark software of vulkan API
  135. RUN apt-get update && apt-get install -y --no-install-recommends \
  136. vulkan-utils firefox openbox menu alsa pulseaudio libgtk2.0-0 && \
  137. apt-get autoclean -y && apt-get autocremove -y && rm -rf /var/lib/apt/lists/*
  138.  
  139. # novnc
  140. # download websockify as well
  141. RUN wget https://github.com/novnc/noVNC/archive/v1.3.0.zip && \
  142. unzip -q v1.3.0.zip && \
  143. rm -rf v1.3.0.zip && \
  144. git clone -b v0.10.0 https://github.com/novnc/websockify /noVNC-1.3.0/utils/websockify
  145.  
  146.  
  147. # Xorg segfault error
  148. # 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)
  149. # related? https://github.com/Microsoft/WSL/issues/2016
  150. RUN apt-get update && apt-get install -y --no-install-recommends \
  151. dbus-x11 libdbus-c++-1-0v5 && \
  152. apt-get autoclean -y && apt-get autocremove -y && rm -rf /var/lib/apt/lists/*
  153.  
  154. RUN echo "alias m='cd /home/$USERNAME ; su $USERNAME'" >> /home/$USERNAME/.bashrc
  155.  
  156. # ROS Melodic
  157. RUN sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
  158. RUN apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
  159. RUN apt-get update && apt-get install -y --no-install-recommends \
  160. ros-melodic-desktop-full \
  161. python-rosdep \
  162. python-rosinstall \
  163. python-rosinstall-generator \
  164. python-wstool && \
  165. apt-get autoclean -y && apt-get autocremove -y && rm -rf /var/lib/apt/lists/*
  166.  
  167. # addtional ROS package
  168. RUN apt-get update && apt-get install -y --no-install-recommends \
  169. ros-melodic-derived-object-msgs \
  170. ros-melodic-ackermann-msgs \
  171. ros-melodic-ainstein-radar-msgs \
  172. python3-numpy \
  173. libomp-dev \
  174. libomp5 && \
  175. apt-get autoclean -y && apt-get autocremove -y && rm -rf /var/lib/apt/lists/*
  176.  
  177. RUN pip install --upgrade setuptools wheel && \
  178. pip install \
  179. simple-pid \
  180. numpy \
  181. pygame \
  182. transforms3d \
  183. future \
  184. matplotlib \
  185. open3d \
  186. pyrsistent==0.16.1 \
  187. psutil \
  188. py-cpuinfo \
  189. python-tr \
  190. xmlschema==1.0.18 \
  191. py-trees==0.8.3 \
  192. Shapely \
  193. mkdocs \
  194. markdown-include \
  195. mkdocs-redirects \
  196. ephem \
  197. tabulate \
  198. networkx && \
  199. rosdep init
  200.  
  201. USER $USERNAME
  202. WORKDIR /home/$USERNAME
  203. RUN rosdep update
  204. COPY CARLA_${CARLA_VERSION_FULL}.tar.gz /home/$USERNAME/
  205. RUN mkdir CARLA_${CARLA_VERSION_FULL} && \
  206. tar xfvz CARLA_${CARLA_VERSION_FULL}.tar.gz -C CARLA_${CARLA_VERSION_FULL} && \
  207. rm /home/$USERNAME/CARLA_${CARLA_VERSION_FULL}.tar.gz
  208.  
  209. #COPY AdditionalMaps_${CARLA_VERSION_FULL}.tar.gz /home/$USERNAME/
  210. #RUN tar xfvz AdditionalMaps_${CARLA_VERSION_FULL}.tar.gz -C /home/$USERNAME/CARLA_${CARLA_VERSION_FULL}/ && \
  211. # rm /home/$USERNAME/AdditionalMaps_${CARLA_VERSION_FULL}.tar.gz
  212.  
  213. 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
  214.  
  215. SHELL ["/bin/bash", "-c"]
  216. RUN mkdir -p ~/catkin_ws/src && \
  217. source /opt/ros/melodic/setup.bash && \
  218. catkin_init_workspace ~/catkin_ws/src && \
  219. cd ~/catkin_ws/src && \
  220. git clone --recursive https://github.com/carla-simulator/ros-bridge.git -b 0.9.11 && \
  221. echo ${CARLA_VERSION} > /home/kbkn/catkin_ws/src/ros-bridge/carla_ros_bridge/src/carla_ros_bridge/CARLA_VERSION && \
  222. cd ~/catkin_ws && \
  223. catkin_make -DCMAKE_BUILD_TYPE=Release && \
  224. source ~/catkin_ws/devel/setup.bash
  225.  
  226. RUN cd /home/$USERNAME && \
  227. git clone https://github.com/carla-simulator/scenario_runner.git -b v${CARLA_VERSION}
  228.  
  229. RUN echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc && \
  230. echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc && \
  231. echo "alias cm='cd ~/catkin_ws;catkin_make'" >> ~/.bashrc && \
  232. echo "alias cs='cd ~/catkin_ws/src'" >> ~/.bashrc && \
  233. echo "export SCENARIO_RUNNER_PATH=/home/$USERNAME/scenario_runner" >> ~/.bashrc && \
  234. pip install -r /home/kbkn/CARLA_${CARLA_VERSION}/PythonAPI/util/requirements.txt && \
  235. pip install -r /home/kbkn/CARLA_${CARLA_VERSION}/PythonAPI/carla/requirements.txt && \
  236. pip install -r /home/kbkn/scenario_runner/requirements.txt
  237.  
  238. USER root
  239. WORKDIR /root
  240. RUN echo "alias m='cd /home/$USERNAME ; su $USERNAME'" >> /root/.bashrc
  241.  
  242.  
  243. COPY startup.sh /startup.sh
  244. COPY scripts/ /home/$USERNAME/scripts/
  245. EXPOSE 5900
  246. EXPOSE 8081
  247.  
  248. CMD ["bash", "/startup.sh"]