Dockerfile 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. ARG NOVNC_VERSION=1.1.0
  10. ENV NOVNC_VERSION $NOVNC_VERSION
  11. # Default password is 'vncpasswd'
  12. ENV VNCPASS vncpasswd
  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. xfonts-base \
  57. xkb-data \
  58. libxtst6 \
  59. libxtst6:i386 \
  60. mlocate \
  61. vim \
  62. htop \
  63. firefox \
  64. qt5-default \
  65. libpci3 \
  66. supervisor \
  67. net-tools \
  68. ubuntu-mate-core \
  69. ubuntu-mate-desktop && \
  70. rm -rf /var/lib/apt/lists/*
  71. RUN apt-get update && apt-get install -y \
  72. xinit && \
  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 host's driver
  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. libvulkan1 vulkan-utils && \
  110. rm -rf /var/lib/apt/lists/*
  111. # Sound driver including PulseAudio and GTK library
  112. # If you want to use sounds on docker, try 'pulseaudio --start'
  113. RUN apt-get update && apt-get install -y --no-install-recommends \
  114. alsa pulseaudio libgtk2.0-0 && \
  115. rm -rf /var/lib/apt/lists/*
  116. # noVNC and Websockify
  117. RUN wget https://github.com/novnc/noVNC/archive/v$NOVNC_VERSION.zip && \
  118. unzip -q v$NOVNC_VERSION.zip && \
  119. rm -rf v$NOVNC_VERSION.zip && \
  120. mv noVNC-$NOVNC_VERSION /opt/noVNC && \
  121. ln -s /opt/noVNC/vnc.html /opt/noVNC/index.html && \
  122. git clone https://github.com/novnc/websockify /opt/noVNC/utils/websockify
  123. # X server segfault error mitigation
  124. RUN apt-get update && apt-get install -y --no-install-recommends \
  125. dbus-x11 \
  126. libdbus-c++-1-0v5 && \
  127. rm -rf /var/lib/apt/lists/*
  128. RUN sed -i "s/allowed_users=console/allowed_users=anybody/;$ a needs_root_rights=yes" /etc/X11/Xwrapper.config
  129. COPY bootstrap.sh /bootstrap.sh
  130. RUN chmod 755 /bootstrap.sh
  131. COPY supervisord.conf /etc/supervisord.conf
  132. RUN chmod 755 /etc/supervisord.conf
  133. # Create user with password '${VNCPASS}'
  134. RUN apt-get update && apt-get install -y --no-install-recommends \
  135. sudo && \
  136. groupadd -g 1000 user && \
  137. useradd -ms /bin/bash user -u 1000 -g 1000 && \
  138. usermod -a -G adm,audio,cdrom,disk,games,lpadmin,sudo,dip,plugdev,tty,video user && \
  139. echo "user ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers && \
  140. chown -R user:user /home/user/ && \
  141. echo "user:${VNCPASS}" | chpasswd && \
  142. rm -rf /var/lib/apt/lists/*
  143. EXPOSE 5901
  144. USER user
  145. WORKDIR /home/user
  146. ENTRYPOINT ["/usr/bin/supervisord"]