Dockerfile 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. FROM ubuntu:20.04
  2. # Based on https://github.com/ryought/glx-docker-headless-gpu/blob/master/Dockerfile
  3. LABEL maintainer "https://github.com/ehfd"
  4. # Make all NVIDIA GPUS visible, but we 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. ENV NVIDIA_DRIVER_CAPABILITIES all
  9. # Default options (password is 'vncpasswd')
  10. ENV VNCPASS vncpasswd
  11. ENV SIZEW 1920
  12. ENV SIZEH 1080
  13. # Install locales to prevent errors
  14. RUN apt-get clean && \
  15. apt-get update && \
  16. apt-get install --no-install-recommends -y locales && \
  17. rm -rf /var/lib/apt/lists/* && \
  18. locale-gen en_US.UTF-8
  19. ENV LANG en_US.UTF-8
  20. ENV LANGUAGE en_US:en
  21. ENV LC_ALL en_US.UTF-8
  22. # Almost same as nvidia/driver https://gitlab.com/nvidia/container-images/driver/-/blob/master/ubuntu20.04/Dockerfile
  23. RUN dpkg --add-architecture i386 && \
  24. apt-get update && apt-get install -y --no-install-recommends \
  25. apt-utils \
  26. build-essential \
  27. ca-certificates \
  28. curl \
  29. kmod \
  30. file \
  31. libc6:i386 \
  32. libelf-dev \
  33. libglvnd-dev \
  34. pkg-config && \
  35. rm -rf /var/lib/apt/lists/*
  36. # Install X server and desktop before driver
  37. RUN apt-get update && apt-get install -y software-properties-common
  38. RUN apt-get install -y \
  39. wget \
  40. gzip \
  41. zip \
  42. unzip \
  43. gcc \
  44. git \
  45. libc6-dev \
  46. libglu1 \
  47. libglu1:i386 \
  48. libsm6 \
  49. libxv1 \
  50. libxv1:i386 \
  51. make \
  52. python \
  53. python-numpy \
  54. python3 \
  55. python3-numpy \
  56. x11-xkb-utils \
  57. xauth \
  58. xinit \
  59. xfonts-base \
  60. xkb-data \
  61. libxtst6 \
  62. libxtst6:i386 \
  63. mlocate \
  64. nano \
  65. vim \
  66. htop \
  67. firefox \
  68. libpci3 \
  69. supervisor \
  70. net-tools \
  71. ubuntu-mate-core \
  72. ubuntu-mate-desktop && \
  73. rm -rf /var/lib/apt/lists/*
  74. # Install NVIDIA drivers, including X graphic drivers by omitting --x-{prefix,module-path,library-path,sysconfig-path}
  75. # Driver version must be equal to the host
  76. #ARG BASE_URL=https://us.download.nvidia.com/tesla
  77. ARG BASE_URL=http://us.download.nvidia.com/XFree86/Linux-x86_64
  78. ENV DRIVER_VERSION 450.66
  79. RUN cd /tmp && \
  80. curl -fSsl -O $BASE_URL/$DRIVER_VERSION/NVIDIA-Linux-x86_64-$DRIVER_VERSION.run && \
  81. sh NVIDIA-Linux-x86_64-$DRIVER_VERSION.run -x && \
  82. cd NVIDIA-Linux-x86_64-$DRIVER_VERSION* && \
  83. ./nvidia-installer --silent \
  84. --no-kernel-module \
  85. --install-compat32-libs \
  86. --no-nouveau-check \
  87. --no-nvidia-modprobe \
  88. --no-rpms \
  89. --no-backup \
  90. --no-check-for-alternate-installs \
  91. --no-libglx-indirect \
  92. --no-install-libglvnd && \
  93. mkdir -p /usr/src/nvidia-$DRIVER_VERSION && \
  94. mv LICENSE mkprecompiled kernel /usr/src/nvidia-$DRIVER_VERSION && \
  95. sed '9,${/^\(kernel\|LICENSE\)/!d}' .manifest > /usr/src/nvidia-$DRIVER_VERSION/.manifest && \
  96. rm -rf /tmp/*
  97. # Install packages related to X server
  98. # pkg-config: nvidia-xconfig requires this package
  99. # mesa-utils: This package includes glxgears and glxinfo, which is useful for testing GLX drivers
  100. # x11vnc: Make connection between X11 server and VNC client.
  101. # x11-apps: xeyes can be used to make sure that X11 server is running.
  102. RUN apt-get update && apt-get install -y --no-install-recommends \
  103. mesa-utils \
  104. x11vnc \
  105. x11-apps && \
  106. rm -rf /var/lib/apt/lists/*
  107. # Install Vulkan
  108. RUN apt-get update && apt-get install -y --no-install-recommends \
  109. libvulkan-dev \
  110. vulkan-validationlayers-dev \
  111. vulkan-utils \
  112. meson && \
  113. rm -rf /var/lib/apt/lists/* && \
  114. cd /tmp && \
  115. git clone https://github.com/aejsmith/vkdevicechooser && \
  116. cd vkdevicechooser && \
  117. meson builddir --prefix=/usr && \
  118. ninja -C builddir && \
  119. meson install -C builddir && \
  120. cd / && rm -rf /tmp/*
  121. # Sound driver including PulseAudio and GTK library
  122. # If you want to use sounds on docker, try 'pulseaudio --start'
  123. RUN apt-get update && apt-get install -y --no-install-recommends \
  124. alsa \
  125. pulseaudio \
  126. libgtk2.0-0 && \
  127. rm -rf /var/lib/apt/lists/*
  128. # noVNC and Websockify
  129. ENV NOVNC_VERSION 1.1.0
  130. RUN wget https://github.com/novnc/noVNC/archive/v$NOVNC_VERSION.zip && \
  131. unzip -q v$NOVNC_VERSION.zip && \
  132. rm -rf v$NOVNC_VERSION.zip && \
  133. mv noVNC-$NOVNC_VERSION /opt/noVNC && \
  134. ln -s /opt/noVNC/vnc.html /opt/noVNC/index.html && \
  135. git clone https://github.com/novnc/websockify /opt/noVNC/utils/websockify
  136. # X server segfault error mitigation
  137. RUN apt-get update && apt-get install -y --no-install-recommends \
  138. dbus-x11 \
  139. libdbus-c++-1-0v5 && \
  140. rm -rf /var/lib/apt/lists/*
  141. RUN sed -i "s/allowed_users=console/allowed_users=anybody/;$ a needs_root_rights=yes" /etc/X11/Xwrapper.config
  142. # Create user with password ${VNCPASS}
  143. RUN apt-get update && apt-get install -y --no-install-recommends \
  144. sudo && \
  145. rm -rf /var/lib/apt/lists/* && \
  146. groupadd -g 1000 user && \
  147. useradd -ms /bin/bash user -u 1000 -g 1000 && \
  148. usermod -a -G adm,audio,cdrom,dialout,dip,fax,floppy,input,lpadmin,netdev,plugdev,render,scanner,ssh,sudo,tape,tty,video,voice user && \
  149. echo "user ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers && \
  150. chown -R user:user /home/user && \
  151. echo "user:${VNCPASS}" | chpasswd
  152. COPY bootstrap.sh /bootstrap.sh
  153. RUN chmod 755 /bootstrap.sh
  154. COPY supervisord.conf /etc/supervisord.conf
  155. RUN chmod 755 /etc/supervisord.conf
  156. EXPOSE 5901
  157. USER user
  158. WORKDIR /home/user
  159. ENTRYPOINT ["/usr/bin/supervisord"]