Newer
Older
glx-docker-headless-gpu / Dockerfile
@kbkn kbkn on 31 Mar 2021 7 KB fix dockerfile
  1. #FROM ubuntu:18.04
  2. FROM nvidia/vulkan:1.1.121-cuda-10.1--ubuntu18.04
  3.  
  4. # Make all NVIDIA GPUS visible, but I want to manually install drivers
  5. ARG NVIDIA_VISIBLE_DEVICES=all
  6. # Supress interactive menu while installing keyboard-configuration
  7. ARG DEBIAN_FRONTEND=noninteractive
  8.  
  9. RUN sed -i 's#http://archive.ubuntu.com/ubuntu/#mirror://mirrors.ubuntu.com/mirrors.txt#' /etc/apt/sources.list;
  10.  
  11. # add new sudo user
  12. ENV USERNAME kbkn
  13. ENV HOME /home/$USERNAME
  14. RUN useradd -m $USERNAME && \
  15. echo "$USERNAME:$USERNAME" | chpasswd && \
  16. usermod --shell /bin/bash $USERNAME && \
  17. usermod -aG sudo $USERNAME && \
  18. mkdir /etc/sudoers.d && \
  19. echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/$USERNAME && \
  20. chmod 0440 /etc/sudoers.d/$USERNAME && \
  21. # Replace 1000 with your user/group id
  22. usermod --uid 1000 $USERNAME && \
  23. groupmod --gid 1000 $USERNAME && \
  24. chown -Rf $USERNAME.$USERNAME /home/$USERNAME && \
  25. mkdir -p /home/$USERNAME/.cache && \
  26. chmod -R 777 /home/$USERNAME/.cache
  27.  
  28. # Error constructing proxy for org.gnome.Terminal:/org/gnome/Terminal/Factory0: Failed to execute child process dbus-launch (No such file or directory)
  29. # fix by setting LANG https://askubuntu.com/questions/608330/problem-with-gnome-terminal-on-gnome-3-12-2
  30. # to install locales https://stackoverflow.com/questions/39760663/docker-ubuntu-bin-sh-1-locale-gen-not-found
  31. RUN apt-get clean && \
  32. apt-get update && \
  33. apt-get install -y locales && \
  34. rm -rf /var/lib/apt/lists/* && \
  35. locale-gen en_US.UTF-8
  36. ENV LANG en_US.UTF-8
  37. ENV LANGUAGE en_US:en
  38. ENV LC_ALL en_US.UTF-8
  39.  
  40. # (1) Install Xorg and NVIDIA driver inside the container
  41. # Almost same procesure as nvidia/driver https://gitlab.com/nvidia/driver/blob/master/ubuntu16.04/Dockerfile
  42.  
  43. # (1-1) Install prerequisites
  44. RUN dpkg --add-architecture i386 && \
  45. apt-get update && apt-get install -y --no-install-recommends \
  46. apt-utils \
  47. build-essential \
  48. ca-certificates \
  49. curl \
  50. wget \
  51. vim \
  52. zip \
  53. unzip \
  54. git \
  55. python \
  56. kmod \
  57. libc6:i386 \
  58. pkg-config \
  59. libelf-dev && \
  60. rm -rf /var/lib/apt/lists/*
  61.  
  62. # (1-2) Install xorg server and xinit BEFORE INSTALLING NVIDIA DRIVER.
  63. # After this installation, command Xorg and xinit can be used in the container
  64. # if you need full ubuntu desktop environment, the line below should be added.
  65. # ubuntu-desktop \
  66. RUN apt-get update && apt-get install -y \
  67. xinit && \
  68. rm -rf /var/lib/apt/lists/*
  69.  
  70. # (1-3) Install NVIDIA drivers, including X graphic drivers
  71. # 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.
  72. # Driver version must be equal to host's driver
  73. # Install the userspace components and copy the kernel module sources.
  74. #ENV DRIVER_VERSION=410.129-diagnostic
  75. #ENV DRIVER_VERSION_PATH=410.129
  76. #RUN cd /tmp && \
  77. # curl -fSsl -O https://us.download.nvidia.com/tesla/$DRIVER_VERSION_PATH/NVIDIA-Linux-x86_64-$DRIVER_VERSION.run && \
  78. # sh NVIDIA-Linux-x86_64-$DRIVER_VERSION.run -x && \
  79. # cd NVIDIA-Linux-x86_64-$DRIVER_VERSION && \
  80. # ./nvidia-installer --silent \
  81. # --no-kernel-module \
  82. # --install-compat32-libs \
  83. # --no-nouveau-check \
  84. # --no-nvidia-modprobe \
  85. # --no-rpms \
  86. # --no-backup \
  87. # --no-check-for-alternate-installs \
  88. # --no-libglx-indirect \
  89. # --no-glvnd-egl-client \
  90. # --no-glvnd-glx-client \
  91. # --no-install-libglvnd && \
  92. # mkdir -p /usr/src/nvidia-$DRIVER_VERSION && \
  93. # mv LICENSE mkprecompiled kernel /usr/src/nvidia-$DRIVER_VERSION && \
  94. # sed '9,${/^\(kernel\|LICENSE\)/!d}' .manifest > /usr/src/nvidia-$DRIVER_VERSION/.manifest
  95. # this option cannot be used on newer driver
  96. # --no-glvnd-egl-client \
  97. # --no-glvnd-glx-client \
  98. 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
  99. RUN cd /tmp && \
  100. wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin && \
  101. mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600 && \
  102. dpkg -i cuda-repo-ubuntu1804-11-2-local_11.2.2-460.32.03-1_amd64.deb && \
  103. apt-key add /var/cuda-repo-ubuntu1804-11-2-local/7fa2af80.pub && \
  104. apt-get update && apt-get install -y --no-install-recommends \
  105. cuda-drivers && \
  106. rm -rf cuda-repo-ubuntu1804-11-2-local_11.2.2-460.32.03-1_amd64.deb && \
  107. rm -rf /var/lib/apt/lists/*
  108.  
  109.  
  110. # (2) Configurate Xorg
  111. # (2-1) Install some necessary softwares
  112. #
  113. # pkg-config: nvidia-xconfig requires this package
  114. # mesa-utils: This package includes glxgears and glxinfo, which is useful for testing GLX drivers
  115. # x11vnc: Make connection between x11 server and VNC client.
  116. # x11-apps: xeyes can be used to make sure that X11 server is running.
  117. #
  118. # Note: x11vnc in ubuntu18.04 is useless beacuse of stack smashing bug. See below to manual compilation.
  119. RUN apt-get update && apt-get install -y --no-install-recommends \
  120. mesa-utils \
  121. x11-apps && \
  122. rm -rf /var/lib/apt/lists/*
  123.  
  124. # solution for the `stack smashing detected` issue
  125. # https://github.com/LibVNC/x11vnc/issues/61
  126. RUN apt-get update && apt-get install -y --no-install-recommends \
  127. automake autoconf libssl-dev xorg-dev libvncserver-dev xdg-user-dirs xdg-utils && \
  128. rm -rf /var/lib/apt/lists/* && \
  129. git clone https://github.com/LibVNC/x11vnc.git && \
  130. cd x11vnc && \
  131. ./autogen.sh && \
  132. make && \
  133. cp src/x11vnc /usr/bin/x11vnc
  134.  
  135. # (2-2) Optional vulkan support
  136. # vulkan-utils includes vulkan-smoketest, benchmark software of vulkan API
  137. RUN apt-get update && apt-get install -y --no-install-recommends \
  138. libvulkan1 vulkan-utils && \
  139. rm -rf /var/lib/apt/lists/*
  140.  
  141. # for test
  142. RUN apt-get update && apt-get install -y --no-install-recommends \
  143. firefox openbox menu && \
  144. rm -rf /var/lib/apt/lists/*
  145.  
  146. # sound driver and GTK library
  147. # If you want to use sounds on docker, try `pulseaudio --start`
  148. RUN apt-get update && apt-get install -y --no-install-recommends \
  149. alsa pulseaudio libgtk2.0-0 && \
  150. rm -rf /var/lib/apt/lists/*
  151.  
  152. # novnc
  153. # download websockify as well
  154. RUN wget https://github.com/novnc/noVNC/archive/v1.1.0.zip && \
  155. unzip -q v1.1.0.zip && \
  156. rm -rf v1.1.0.zip && \
  157. git clone https://github.com/novnc/websockify /noVNC-1.1.0/utils/websockify
  158.  
  159. # Xorg segfault error
  160. # 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)
  161. # related? https://github.com/Microsoft/WSL/issues/2016
  162. RUN apt-get update && apt-get install -y --no-install-recommends \
  163. dbus-x11 \
  164. libdbus-c++-1-0v5 \
  165. software-properties-common && \
  166. rm -rf /var/lib/apt/lists/*
  167.  
  168. # (3) Run Xorg server + x11vnc + X applications
  169. # see run.sh for details
  170. RUN echo "alias m='cd /home/$USERNAME ; su $USERNAME'" >> /home/kbkn/.bashrc && \
  171. apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 1AF1527DE64CB8D9 && \
  172. add-apt-repository "deb [arch=amd64] http://dist.carla.org/carla $(lsb_release -sc) main" && \
  173. mkdir -p /opt/carla-simulator && \
  174. cd /opt/carla-simulator && \
  175. apt-get update && apt-get install -y --no-install-recommends \
  176. carla-simulator=0.9.10-1 && \
  177. rm -rf /var/lib/apt/lists/*
  178. COPY run.sh /run.sh
  179. CMD ["bash", "/run.sh"]