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