Newer
Older
glx-docker-headless-gpu / Dockerfile
@ikko.k.kobayashi ikko.k.kobayashi on 3 Apr 2021 9 KB fix
  1. FROM ubuntu:18.04
  2. #FROM nvidia/opengl:1.2-glvnd-runtime-ubuntu18.04
  3. #FROM nvidia/vulkan:1.1.121-cuda-10.1--ubuntu18.04
  4.  
  5. # Make all NVIDIA GPUS visible, but I want to manually install drivers
  6. ARG NVIDIA_VISIBLE_DEVICES=all
  7. # Supress interactive menu while installing keyboard-configuration
  8. ARG DEBIAN_FRONTEND=noninteractive
  9.  
  10. RUN sed -i 's#http://archive.ubuntu.com/ubuntu/#mirror://mirrors.ubuntu.com/mirrors.txt#' /etc/apt/sources.list;
  11.  
  12. # add new sudo user
  13. ENV USERNAME kbkn
  14. ENV HOME /home/$USERNAME
  15. RUN useradd -m $USERNAME && \
  16. echo "$USERNAME:$USERNAME" | 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. chown -Rf $USERNAME.$USERNAME /home/$USERNAME && \
  26. mkdir -p /home/$USERNAME/.cache && \
  27. chmod -R 777 /home/$USERNAME/.cache
  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 packages='libsdl2-2.0 xserver-xorg libvulkan1' \
  49. && apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y $packages --no-install-recommends \
  50. && VULKAN_API_VERSION=`dpkg -s libvulkan1 | grep -oP 'Version: [0-9|\.]+' | grep -oP '[0-9|\.]+'` && \
  51. mkdir -p /etc/vulkan/icd.d/ && \
  52. echo \
  53. "{\
  54. \"file_format_version\" : \"1.0.0\",\
  55. \"ICD\": {\
  56. \"library_path\": \"libGLX_nvidia.so.0\",\
  57. \"api_version\" : \"${VULKAN_API_VERSION}\"\
  58. }\
  59. }" > /etc/vulkan/icd.d/nvidia_icd.json \
  60. && rm -rf /var/lib/apt/lists/*
  61.  
  62. # Error constructing proxy for org.gnome.Terminal:/org/gnome/Terminal/Factory0: Failed to execute child process dbus-launch (No such file or directory)
  63. # fix by setting LANG https://askubuntu.com/questions/608330/problem-with-gnome-terminal-on-gnome-3-12-2
  64. # to install locales https://stackoverflow.com/questions/39760663/docker-ubuntu-bin-sh-1-locale-gen-not-found
  65. RUN apt-get clean && \
  66. apt-get update && \
  67. apt-get install -y locales && \
  68. rm -rf /var/lib/apt/lists/* && \
  69. locale-gen en_US.UTF-8
  70. ENV LANG en_US.UTF-8
  71. ENV LANGUAGE en_US:en
  72. ENV LC_ALL en_US.UTF-8
  73.  
  74. # (1) Install Xorg and NVIDIA driver inside the container
  75. # Almost same procesure as nvidia/driver https://gitlab.com/nvidia/driver/blob/master/ubuntu16.04/Dockerfile
  76.  
  77. # (1-1) Install prerequisites
  78. RUN dpkg --add-architecture i386 && \
  79. apt-get update && apt-get install -y --no-install-recommends \
  80. apt-utils \
  81. build-essential \
  82. ca-certificates \
  83. curl \
  84. wget \
  85. vim \
  86. zip \
  87. unzip \
  88. git \
  89. kmod \
  90. libc6:i386 \
  91. pkg-config \
  92. libelf-dev && \
  93. rm -rf /var/lib/apt/lists/*
  94.  
  95. # (1-2) Install xorg server and xinit BEFORE INSTALLING NVIDIA DRIVER.
  96. # After this installation, command Xorg and xinit can be used in the container
  97. # if you need full ubuntu desktop environment, the line below should be added.
  98. # ubuntu-desktop \
  99. RUN apt-get update && apt-get install -y \
  100. xinit && \
  101. rm -rf /var/lib/apt/lists/*
  102.  
  103. # (1-3) Install NVIDIA drivers, including X graphic drivers
  104. # 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.
  105. # Driver version must be equal to host's driver
  106. # Install the userspace components and copy the kernel module sources.
  107. #ENV DRIVER_VERSION=410.129-diagnostic
  108. #ENV DRIVER_VERSION_PATH=410.129
  109. #RUN cd /tmp && \
  110. # curl -fSsl -O https://us.download.nvidia.com/tesla/$DRIVER_VERSION_PATH/NVIDIA-Linux-x86_64-$DRIVER_VERSION.run && \
  111. # sh NVIDIA-Linux-x86_64-$DRIVER_VERSION.run -x && \
  112. # cd NVIDIA-Linux-x86_64-$DRIVER_VERSION && \
  113. # ./nvidia-installer --silent \
  114. # --no-kernel-module \
  115. # --install-compat32-libs \
  116. # --no-nouveau-check \
  117. # --no-nvidia-modprobe \
  118. # --no-rpms \
  119. # --no-backup \
  120. # --no-check-for-alternate-installs \
  121. # --no-libglx-indirect \
  122. # --no-glvnd-egl-client \
  123. # --no-glvnd-glx-client \
  124. # --no-install-libglvnd && \
  125. # mkdir -p /usr/src/nvidia-$DRIVER_VERSION && \
  126. # mv LICENSE mkprecompiled kernel /usr/src/nvidia-$DRIVER_VERSION && \
  127. # sed '9,${/^\(kernel\|LICENSE\)/!d}' .manifest > /usr/src/nvidia-$DRIVER_VERSION/.manifest
  128. # this option cannot be used on newer driver
  129. # --no-glvnd-egl-client \
  130. # --no-glvnd-glx-client \
  131. 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
  132. RUN cd /tmp && \
  133. wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin && \
  134. mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600 && \
  135. dpkg -i cuda-repo-ubuntu1804-11-2-local_11.2.2-460.32.03-1_amd64.deb && \
  136. apt-key add /var/cuda-repo-ubuntu1804-11-2-local/7fa2af80.pub && \
  137. apt-get update && apt-get install -y --no-install-recommends \
  138. cuda-drivers && \
  139. rm -rf cuda-repo-ubuntu1804-11-2-local_11.2.2-460.32.03-1_amd64.deb && \
  140. rm -rf /var/lib/apt/lists/*
  141.  
  142.  
  143. # (2) Configurate Xorg
  144. # (2-1) Install some necessary softwares
  145. #
  146. # pkg-config: nvidia-xconfig requires this package
  147. # mesa-utils: This package includes glxgears and glxinfo, which is useful for testing GLX drivers
  148. # x11vnc: Make connection between x11 server and VNC client.
  149. # x11-apps: xeyes can be used to make sure that X11 server is running.
  150. #
  151. # Note: x11vnc in ubuntu18.04 is useless beacuse of stack smashing bug. See below to manual compilation.
  152. RUN apt-get update && apt-get install -y --no-install-recommends \
  153. mesa-utils \
  154. x11-apps && \
  155. rm -rf /var/lib/apt/lists/*
  156.  
  157. # solution for the `stack smashing detected` issue
  158. # https://github.com/LibVNC/x11vnc/issues/61
  159. RUN apt-get update && apt-get install -y --no-install-recommends \
  160. automake autoconf libssl-dev xorg-dev libvncserver-dev xdg-user-dirs xdg-utils && \
  161. rm -rf /var/lib/apt/lists/* && \
  162. git clone https://github.com/LibVNC/x11vnc.git && \
  163. cd x11vnc && \
  164. ./autogen.sh && \
  165. make && \
  166. cp src/x11vnc /usr/bin/x11vnc
  167.  
  168. # (2-2) Optional vulkan support
  169. # vulkan-utils includes vulkan-smoketest, benchmark software of vulkan API
  170. RUN apt-get update && apt-get install -y --no-install-recommends \
  171. vulkan-utils && \
  172. rm -rf /var/lib/apt/lists/*
  173.  
  174. # for test
  175. RUN apt-get update && apt-get install -y --no-install-recommends \
  176. firefox openbox menu && \
  177. rm -rf /var/lib/apt/lists/*
  178.  
  179. # sound driver and GTK library
  180. # If you want to use sounds on docker, try `pulseaudio --start`
  181. RUN apt-get update && apt-get install -y --no-install-recommends \
  182. alsa pulseaudio libgtk2.0-0 && \
  183. rm -rf /var/lib/apt/lists/*
  184.  
  185. # novnc
  186. # download websockify as well
  187. RUN wget https://github.com/novnc/noVNC/archive/v1.2.0.zip && \
  188. unzip -q v1.2.0.zip && \
  189. rm -rf v1.2.0.zip && \
  190. git clone https://github.com/novnc/websockify /noVNC-1.2.0/utils/websockify
  191. # Xorg segfault error
  192. # 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)
  193. # related? https://github.com/Microsoft/WSL/issues/2016
  194. RUN apt-get update && apt-get install -y --no-install-recommends \
  195. dbus-x11 \
  196. libdbus-c++-1-0v5 && \
  197. rm -rf /var/lib/apt/lists/*
  198.  
  199. # (3) Run Xorg server + x11vnc + X applications
  200. # see run.sh for details
  201. RUN echo "alias m='cd /home/$USERNAME ; su $USERNAME'" >> /home/kbkn/.bashrc && \
  202. apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 1AF1527DE64CB8D9 && \
  203. add-apt-repository "deb [arch=amd64] http://dist.carla.org/carla $(lsb_release -sc) main" && \
  204. mkdir -p /opt/carla-simulator && \
  205. cd /opt/carla-simulator && \
  206. apt-get update && apt-get install -y --no-install-recommends \
  207. carla-simulator=0.9.10-1 \
  208. libxerces-c-dev iproute2 && \
  209. rm -rf /var/lib/apt/lists/* && \
  210. 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
  211. RUN pip install --upgrade setuptools wheel && \
  212. pip install simple-pid \
  213. numpy \
  214. pygame \
  215. future \
  216. matplotlib \
  217. open3d \
  218. pyrsistent==0.16.1 \
  219. psutil \
  220. py-cpuinfo \
  221. python-tr \
  222. xmlschema==1.0.18 \
  223. py-trees==0.8.3 \
  224. Shapely \
  225. mkdocs \
  226. markdown-include \
  227. mkdocs-redirects \
  228. networkx \
  229. transforms3d \
  230. decorator==5.0.0
  231. COPY AdditionalMaps_0.9.10.1.tar.gz /home/$USERNAME/
  232. RUN tar xfvz /home/$USERNAME/AdditionalMaps_0.9.10.1.tar.gz -C /opt/carla-simulator/ && \
  233. rm /home/$USERNAME/AdditionalMaps_0.9.10.1.tar.gz
  234. RUN mkdir -p /home/$USERNAME/.config && \
  235. chmod -R 777 /home/$USERNAME/.config && \
  236. mkdir -p /home/$USERNAME/.cache && \
  237. chmod -R 777 /home/$USERNAME/.cache
  238. COPY run.sh /run.sh
  239. EXPOSE 5900
  240. EXPOSE 8081
  241. CMD ["bash", "/run.sh"]