Dockerfile 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. x11-xkb-utils \
  55. xauth \
  56. xinit \
  57. xfonts-base \
  58. xkb-data \
  59. libxtst6 \
  60. libxtst6:i386 \
  61. mlocate \
  62. nano \
  63. vim \
  64. htop \
  65. firefox \
  66. libpci3 \
  67. supervisor \
  68. net-tools \
  69. ubuntu-mate-core \
  70. ubuntu-mate-desktop && \
  71. rm -rf /var/lib/apt/lists/*
  72. # Install NVIDIA drivers, including X graphic drivers by omitting --x-{prefix,module-path,library-path,sysconfig-path}
  73. # Driver version must be equal to the host
  74. #ARG BASE_URL=https://us.download.nvidia.com/tesla
  75. ARG BASE_URL=http://us.download.nvidia.com/XFree86/Linux-x86_64
  76. ENV DRIVER_VERSION 450.66
  77. RUN cd /tmp && \
  78. curl -fSsl -O $BASE_URL/$DRIVER_VERSION/NVIDIA-Linux-x86_64-$DRIVER_VERSION.run && \
  79. sh NVIDIA-Linux-x86_64-$DRIVER_VERSION.run -x && \
  80. cd NVIDIA-Linux-x86_64-$DRIVER_VERSION* && \
  81. ./nvidia-installer --silent \
  82. --no-kernel-module \
  83. --install-compat32-libs \
  84. --no-nouveau-check \
  85. --no-nvidia-modprobe \
  86. --no-rpms \
  87. --no-backup \
  88. --no-check-for-alternate-installs \
  89. --no-libglx-indirect \
  90. --no-install-libglvnd && \
  91. mkdir -p /usr/src/nvidia-$DRIVER_VERSION && \
  92. mv LICENSE mkprecompiled kernel /usr/src/nvidia-$DRIVER_VERSION && \
  93. sed '9,${/^\(kernel\|LICENSE\)/!d}' .manifest > /usr/src/nvidia-$DRIVER_VERSION/.manifest && \
  94. rm -rf /tmp/*
  95. # Install packages related to X server
  96. # pkg-config: nvidia-xconfig requires this package
  97. # mesa-utils: This package includes glxgears and glxinfo, which is useful for testing GLX drivers
  98. # x11vnc: Make connection between X11 server and VNC client.
  99. # x11-apps: xeyes can be used to make sure that X11 server is running.
  100. RUN apt-get update && apt-get install -y --no-install-recommends \
  101. mesa-utils \
  102. x11vnc \
  103. x11-apps && \
  104. rm -rf /var/lib/apt/lists/*
  105. # Install Vulkan
  106. RUN apt-get update && apt-get install -y --no-install-recommends \
  107. libvulkan-dev \
  108. vulkan-validationlayers-dev \
  109. vulkan-utils \
  110. meson && \
  111. rm -rf /var/lib/apt/lists/* && \
  112. cd /tmp && \
  113. git clone https://github.com/aejsmith/vkdevicechooser && \
  114. cd vkdevicechooser && \
  115. meson builddir --prefix=/usr && \
  116. ninja -C builddir && \
  117. meson install -C builddir && \
  118. cd / && rm -rf /tmp/*
  119. # Sound driver including PulseAudio and GTK library
  120. # If you want to use sounds on docker, try 'pulseaudio --start'
  121. RUN apt-get update && apt-get install -y --no-install-recommends \
  122. alsa \
  123. pulseaudio \
  124. libgtk2.0-0 && \
  125. rm -rf /var/lib/apt/lists/*
  126. # noVNC and Websockify
  127. ENV NOVNC_VERSION 1.1.0
  128. RUN wget https://github.com/novnc/noVNC/archive/v$NOVNC_VERSION.zip && \
  129. unzip -q v$NOVNC_VERSION.zip && \
  130. rm -rf v$NOVNC_VERSION.zip && \
  131. mv noVNC-$NOVNC_VERSION /opt/noVNC && \
  132. ln -s /opt/noVNC/vnc.html /opt/noVNC/index.html && \
  133. git clone https://github.com/novnc/websockify /opt/noVNC/utils/websockify
  134. # X server segfault error mitigation
  135. RUN apt-get update && apt-get install -y --no-install-recommends \
  136. dbus-x11 \
  137. libdbus-c++-1-0v5 && \
  138. rm -rf /var/lib/apt/lists/*
  139. RUN sed -i "s/allowed_users=console/allowed_users=anybody/;$ a needs_root_rights=yes" /etc/X11/Xwrapper.config
  140. # Create user with password ${VNCPASS}
  141. RUN apt-get update && apt-get install -y --no-install-recommends \
  142. sudo && \
  143. rm -rf /var/lib/apt/lists/* && \
  144. groupadd -g 1000 user && \
  145. useradd -ms /bin/bash user -u 1000 -g 1000 && \
  146. usermod -a -G adm,audio,cdrom,dialout,dip,fax,floppy,input,lpadmin,netdev,plugdev,render,scanner,ssh,sudo,tape,tty,video,voice user && \
  147. echo "user ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers && \
  148. chown -R user:user /home/user && \
  149. echo "user:${VNCPASS}" | chpasswd
  150. COPY bootstrap.sh /bootstrap.sh
  151. RUN chmod 755 /bootstrap.sh
  152. COPY supervisord.conf /etc/supervisord.conf
  153. RUN chmod 755 /etc/supervisord.conf
  154. EXPOSE 5901
  155. USER user
  156. WORKDIR /home/user
  157. ENTRYPOINT ["/usr/bin/supervisord"]