Newer
Older
glx-docker-headless-gpu / Dockerfile
@ikko ikko on 14 Oct 2022 11 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 --allow-unauthenticated \
  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 autoremove -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 --allow-unauthenticated && \
  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 autoremove -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 --allow-unauthenticated \
  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 autoremove -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.  
  108. # wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin && \
  109. # mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600 && \
  110. # wget https://developer.download.nvidia.com/compute/cuda/11.6.1/local_installers/cuda-repo-ubuntu1804-11-6-local_11.6.1-510.47.03-1_amd64.deb && \
  111. # dpkg -i cuda-repo-ubuntu1804-11-6-local_11.6.1-510.47.03-1_amd64.deb && \
  112. # apt-key add /var/cuda-repo-ubuntu1804-11-6-local/7fa2af80.pub
  113.  
  114. #RUN cd /tmp && \
  115. # wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin && \
  116. # mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600 && \
  117. # wget https://developer.download.nvidia.com/compute/cuda/11.7.0/local_installers/cuda-repo-ubuntu1804-11-7-local_11.7.0-515.43.04-1_amd64.deb && \
  118. # dpkg -i cuda-repo-ubuntu1804-11-7-local_11.7.0-515.43.04-1_amd64.deb && \
  119. # cp /var/cuda-repo-ubuntu1804-11-7-local/cuda-*-keyring.gpg /usr/share/keyrings/
  120.  
  121. RUN cd /tmp && \
  122. wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin && \
  123. mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600 && \
  124. wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda-repo-ubuntu1804-11-8-local_11.8.0-520.61.05-1_amd64.deb && \
  125. dpkg -i cuda-repo-ubuntu1804-11-8-local_11.8.0-520.61.05-1_amd64.deb && \
  126. cp /var/cuda-repo-ubuntu1804-11-8-local/cuda-*-keyring.gpg /usr/share/keyrings/
  127.  
  128. RUN apt-get update && apt-get install -y --no-install-recommends --allow-unauthenticated \
  129. cuda-drivers && \
  130. apt-get autoclean -y && apt-get autoremove -y && rm -rf /var/lib/apt/lists/*
  131.  
  132. # (2) Configurate Xorg
  133. # (2-1) Install some necessary softwares
  134. #
  135. # pkg-config: nvidia-xconfig requires this package
  136. # mesa-utils: This package includes glxgears and glxinfo, which is useful for testing GLX drivers
  137. # x11vnc: Make connection between x11 server and VNC client.
  138. # x11-apps: xeyes can be used to make sure that X11 server is running.
  139. #
  140. # Note: x11vnc in ubuntu18.04 is useless beacuse of stack smashing bug. See below to manual compilation.
  141.  
  142. RUN apt-get update && apt-get install -y --no-install-recommends --allow-unauthenticated \
  143. mesa-utils lxterminal gnome-tweak-tool x11-apps \
  144. automake autoconf libssl-dev xorg-dev libvncserver-dev \
  145. xdg-user-dirs xdg-utils && \
  146. apt-get autoclean -y && apt-get autoremove -y && rm -rf /var/lib/apt/lists/* && \
  147. git clone -b 0.9.16 https://github.com/LibVNC/x11vnc.git && \
  148. cd x11vnc && \
  149. ./autogen.sh && \
  150. make && \
  151. cp src/x11vnc /usr/bin/x11vnc
  152.  
  153. # (2-2) Optional vulkan support
  154. # vulkan-utils includes vulkan-smoketest, benchmark software of vulkan API
  155. RUN apt-get update && apt-get install -y --no-install-recommends --allow-unauthenticated \
  156. vulkan-utils firefox openbox menu alsa pulseaudio libgtk2.0-0 && \
  157. apt-get autoclean -y && apt-get autoremove -y && rm -rf /var/lib/apt/lists/*
  158.  
  159. # novnc
  160. # download websockify as well
  161. RUN wget https://github.com/novnc/noVNC/archive/v1.3.0.zip && \
  162. unzip -q v1.3.0.zip && \
  163. rm -rf v1.3.0.zip && \
  164. git clone -b v0.10.0 https://github.com/novnc/websockify /noVNC-1.3.0/utils/websockify
  165.  
  166.  
  167. # Xorg segfault error
  168. # 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)
  169. # related? https://github.com/Microsoft/WSL/issues/2016
  170. RUN apt-get update && apt-get install -y --no-install-recommends --allow-unauthenticated \
  171. dbus-x11 libdbus-c++-1-0v5 && \
  172. apt-get autoclean -y && apt-get autoremove -y && rm -rf /var/lib/apt/lists/*
  173.  
  174. RUN echo "alias m='cd /home/$USERNAME ; su $USERNAME'" >> /home/$USERNAME/.bashrc
  175.  
  176. # ROS Melodic
  177. RUN sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
  178. RUN apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
  179. RUN apt-get update && apt-get install -y --no-install-recommends --allow-unauthenticated \
  180. ros-melodic-desktop-full \
  181. python-rosdep \
  182. python-rosinstall \
  183. python-rosinstall-generator \
  184. python-wstool && \
  185. apt-get autoclean -y && apt-get autoremove -y && rm -rf /var/lib/apt/lists/*
  186.  
  187. # addtional ROS package
  188. RUN apt-get update && apt-get install -y --no-install-recommends --allow-unauthenticated \
  189. ros-melodic-derived-object-msgs ros-melodic-ackermann-msgs \
  190. ros-melodic-ainstein-radar-msgs python3-numpy \
  191. libomp-dev libomp5 && \
  192. apt-get autoclean -y && apt-get autoremove -y && rm -rf /var/lib/apt/lists/*
  193.  
  194. RUN pip install --upgrade setuptools wheel && \
  195. pip install \
  196. simple-pid \
  197. numpy \
  198. pygame \
  199. transforms3d \
  200. future \
  201. matplotlib \
  202. open3d \
  203. pyrsistent==0.16.1 \
  204. psutil \
  205. py-cpuinfo \
  206. python-tr \
  207. xmlschema==1.0.18 \
  208. py-trees==0.8.3 \
  209. Shapely \
  210. mkdocs \
  211. markdown-include \
  212. mkdocs-redirects \
  213. ephem \
  214. tabulate \
  215. networkx && \
  216. rosdep init
  217.  
  218. USER $USERNAME
  219. WORKDIR /home/$USERNAME
  220. RUN rosdep update
  221. COPY CARLA_${CARLA_VERSION_FULL}.tar.gz /home/$USERNAME/
  222. RUN mkdir CARLA_${CARLA_VERSION_FULL} && \
  223. tar xfvz CARLA_${CARLA_VERSION_FULL}.tar.gz -C CARLA_${CARLA_VERSION_FULL} && \
  224. rm /home/$USERNAME/CARLA_${CARLA_VERSION_FULL}.tar.gz
  225.  
  226. #COPY AdditionalMaps_${CARLA_VERSION_FULL}.tar.gz /home/$USERNAME/
  227. #RUN tar xfvz AdditionalMaps_${CARLA_VERSION_FULL}.tar.gz -C /home/$USERNAME/CARLA_${CARLA_VERSION_FULL}/ && \
  228. # rm /home/$USERNAME/AdditionalMaps_${CARLA_VERSION_FULL}.tar.gz
  229.  
  230. 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
  231.  
  232. SHELL ["/bin/bash", "-c"]
  233. RUN mkdir -p ~/catkin_ws/src && \
  234. source /opt/ros/melodic/setup.bash && \
  235. catkin_init_workspace ~/catkin_ws/src && \
  236. cd ~/catkin_ws/src && \
  237. git clone --recursive https://github.com/carla-simulator/ros-bridge.git -b 0.9.11 && \
  238. echo ${CARLA_VERSION} > /home/kbkn/catkin_ws/src/ros-bridge/carla_ros_bridge/src/carla_ros_bridge/CARLA_VERSION && \
  239. cd ~/catkin_ws && \
  240. catkin_make -DCMAKE_BUILD_TYPE=Release && \
  241. source ~/catkin_ws/devel/setup.bash
  242.  
  243. RUN cd /home/$USERNAME && \
  244. git clone https://github.com/carla-simulator/scenario_runner.git -b v${CARLA_VERSION}
  245.  
  246. RUN echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc && \
  247. echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc && \
  248. echo "alias cm='cd ~/catkin_ws;catkin_make'" >> ~/.bashrc && \
  249. echo "alias cs='cd ~/catkin_ws/src'" >> ~/.bashrc && \
  250. echo "export SCENARIO_RUNNER_PATH=/home/$USERNAME/scenario_runner" >> ~/.bashrc && \
  251. pip install -r /home/kbkn/CARLA_${CARLA_VERSION}/PythonAPI/util/requirements.txt && \
  252. pip install -r /home/kbkn/CARLA_${CARLA_VERSION}/PythonAPI/carla/requirements.txt && \
  253. pip install -r /home/kbkn/scenario_runner/requirements.txt
  254. USER root
  255. WORKDIR /root
  256. RUN echo "alias m='cd /home/$USERNAME ; su $USERNAME'" >> /root/.bashrc
  257.  
  258.  
  259. COPY startup.sh /startup.sh
  260. COPY scripts/ /home/$USERNAME/scripts/
  261. EXPOSE 5900
  262. EXPOSE 8081
  263.  
  264. CMD ["bash", "/startup.sh"]