Dockerfile 5.4 KB

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