Dockerfile 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. # syntax=docker/dockerfile:1.7
  2. # Final target:
  3. # Ubuntu 24.04 + NVIDIA GLX + XFCE + PipeWire + Firefox + Selkies
  4. #
  5. # The build uses intermediate stages, but produces a single final image.
  6. ARG DISTRIB_RELEASE=24.04
  7. ARG SELKIES_IMAGE=ghcr.io/selkies-project/selkies/py-build:main
  8. ARG SELKIES_GIT_REF=main
  9. ARG NVIDIA_VAAPI_DRIVER_VERSION=latest
  10. # -----------------------------------------------------------------------------
  11. # Current Selkies wheel
  12. # -----------------------------------------------------------------------------
  13. FROM ${SELKIES_IMAGE} AS selkies-build
  14. # -----------------------------------------------------------------------------
  15. # Selkies joystick interposer
  16. # -----------------------------------------------------------------------------
  17. # Build the Selkies joystick interposer directly from its official source.
  18. FROM docker.io/library/ubuntu:${DISTRIB_RELEASE} AS selkies-js-interposer-builder
  19. ARG DEBIAN_FRONTEND=noninteractive
  20. ARG SELKIES_GIT_REF
  21. SHELL ["/bin/bash", "-o", "pipefail", "-c"]
  22. RUN apt-get update \
  23. && apt-get install --no-install-recommends -y \
  24. build-essential \
  25. ca-certificates \
  26. curl \
  27. && rm -rf /var/lib/apt/lists/*
  28. RUN set -eux; \
  29. curl -fsSL \
  30. "https://raw.githubusercontent.com/selkies-project/selkies/${SELKIES_GIT_REF}/addons/js-interposer/joystick_interposer.c" \
  31. -o /tmp/joystick_interposer.c; \
  32. install -d -m 0755 /out; \
  33. gcc -shared -fPIC -O2 \
  34. -Wl,-z,relro,-z,now \
  35. -o /out/selkies_joystick_interposer.so \
  36. /tmp/joystick_interposer.c \
  37. -ldl; \
  38. test -s /out/selkies_joystick_interposer.so
  39. # -----------------------------------------------------------------------------
  40. # Build the current nvidia-vaapi-driver without retaining build dependencies
  41. # -----------------------------------------------------------------------------
  42. FROM docker.io/library/ubuntu:${DISTRIB_RELEASE} AS nvidia-vaapi-builder
  43. ARG DEBIAN_FRONTEND=noninteractive
  44. ARG NVIDIA_VAAPI_DRIVER_VERSION
  45. SHELL ["/bin/bash", "-o", "pipefail", "-c"]
  46. RUN apt-get update \
  47. && apt-get install --no-install-recommends -y \
  48. ca-certificates \
  49. curl \
  50. jq \
  51. meson \
  52. ninja-build \
  53. pkg-config \
  54. libdrm-dev \
  55. libegl-dev \
  56. libffmpeg-nvenc-dev \
  57. libgstreamer-plugins-bad1.0-dev \
  58. libva-dev \
  59. && rm -rf /var/lib/apt/lists/*
  60. RUN set -eux; \
  61. version="${NVIDIA_VAAPI_DRIVER_VERSION}"; \
  62. if [[ "${version}" == "latest" ]]; then \
  63. version="$(curl -fsSL https://api.github.com/repos/elFarto/nvidia-vaapi-driver/releases/latest \
  64. | jq -r '.tag_name' \
  65. | sed 's/^v//')"; \
  66. fi; \
  67. curl -fsSL \
  68. "https://github.com/elFarto/nvidia-vaapi-driver/archive/refs/tags/v${version}.tar.gz" \
  69. -o /tmp/nvidia-vaapi-driver.tar.gz; \
  70. mkdir -p /tmp/nvidia-vaapi-driver; \
  71. tar -xzf /tmp/nvidia-vaapi-driver.tar.gz \
  72. --strip-components=1 \
  73. -C /tmp/nvidia-vaapi-driver; \
  74. cd /tmp/nvidia-vaapi-driver; \
  75. meson setup build \
  76. --prefix=/usr \
  77. --buildtype=release; \
  78. meson compile -C build; \
  79. DESTDIR=/out meson install -C build
  80. # -----------------------------------------------------------------------------
  81. # Final image
  82. # -----------------------------------------------------------------------------
  83. FROM docker.io/library/ubuntu:${DISTRIB_RELEASE}
  84. ARG DEBIAN_FRONTEND=noninteractive
  85. ARG DISTRIB_RELEASE
  86. ARG TZ=UTC
  87. ARG USER_NAME=ubuntu
  88. ARG USER_UID=1000
  89. ARG USER_GID=1000
  90. LABEL org.opencontainers.image.title="Selkies NVIDIA XFCE Desktop" \
  91. org.opencontainers.image.description="XFCE remote desktop with Selkies, PipeWire and NVIDIA acceleration" \
  92. org.opencontainers.image.source="https://github.com/selkies-project/selkies"
  93. SHELL ["/bin/bash", "-o", "pipefail", "-c"]
  94. ENV TZ="${TZ}" \
  95. LANG="en_US.UTF-8" \
  96. LANGUAGE="en_US:en" \
  97. LC_ALL="en_US.UTF-8" \
  98. PASSWD="mypasswd" \
  99. DISPLAY=":20" \
  100. DISPLAY_SIZEW="1920" \
  101. DISPLAY_SIZEH="1080" \
  102. DISPLAY_REFRESH="60" \
  103. DISPLAY_DPI="96" \
  104. DISPLAY_CDEPTH="24" \
  105. VIDEO_PORT="DFP" \
  106. DESKTOP_SESSION="xfce" \
  107. XDG_SESSION_DESKTOP="xfce" \
  108. XDG_CURRENT_DESKTOP="XFCE" \
  109. XDG_SESSION_TYPE="x11" \
  110. SELKIES_MODE="websockets" \
  111. SELKIES_PORT="8080" \
  112. SELKIES_ENCODER="h264enc" \
  113. SELKIES_ENABLE_RESIZE="false" \
  114. SELKIES_ENABLE_BASIC_AUTH="true" \
  115. NVIDIA_VISIBLE_DEVICES="all" \
  116. NVIDIA_DRIVER_CAPABILITIES="all" \
  117. __GL_SYNC_TO_VBLANK="0" \
  118. __GLX_VENDOR_LIBRARY_NAME="nvidia" \
  119. LIBVA_DRIVER_NAME="nvidia" \
  120. NVD_BACKEND="direct" \
  121. MOZ_DISABLE_RDD_SANDBOX="1" \
  122. MOZ_X11_EGL="1" \
  123. PIPEWIRE_LATENCY="128/48000" \
  124. XDG_RUNTIME_DIR="/tmp/runtime-ubuntu" \
  125. PIPEWIRE_RUNTIME_DIR="/tmp/runtime-ubuntu" \
  126. PULSE_RUNTIME_PATH="/tmp/runtime-ubuntu/pulse" \
  127. PULSE_SERVER="unix:/tmp/runtime-ubuntu/pulse/native" \
  128. DBUS_SYSTEM_BUS_ADDRESS="unix:path=/tmp/runtime-ubuntu/dbus-system-bus" \
  129. APPIMAGE_EXTRACT_AND_RUN="1" \
  130. SUDO_EDITOR="mousepad"
  131. # Bootstrap packages needed to configure APT repositories.
  132. RUN apt-get update \
  133. && apt-get install --no-install-recommends -y \
  134. ca-certificates \
  135. curl \
  136. gnupg \
  137. locales \
  138. ssl-cert \
  139. tzdata \
  140. && locale-gen en_US.UTF-8 \
  141. && ln -snf "/usr/share/zoneinfo/${TZ}" /etc/localtime \
  142. && echo "${TZ}" > /etc/timezone \
  143. && rm -rf /var/lib/apt/lists/*
  144. # Keep the same Mozilla and PipeWire repositories as the original image.
  145. RUN install -d -m 0755 \
  146. /etc/apt/preferences.d \
  147. /etc/apt/sources.list.d \
  148. /etc/apt/trusted.gpg.d \
  149. && printf '%s\n' \
  150. 'Package: firefox*' \
  151. 'Pin: version 1:1snap*' \
  152. 'Pin-Priority: -1' \
  153. > /etc/apt/preferences.d/firefox-nosnap \
  154. && curl -fsSL \
  155. 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x738BEB9321D1AAEC13EA9391AEBDF4819BE21867' \
  156. | gpg --dearmor \
  157. > /etc/apt/trusted.gpg.d/mozillateam-ubuntu-ppa.gpg \
  158. && echo \
  159. "deb https://ppa.launchpadcontent.net/mozillateam/ppa/ubuntu noble main" \
  160. > /etc/apt/sources.list.d/mozillateam-ubuntu-ppa.list \
  161. && curl -fsSL \
  162. 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xFC43B7352BCC0EC8AF2EEB8B25088A0359807596' \
  163. | gpg --dearmor \
  164. > /etc/apt/trusted.gpg.d/pipewire-debian-ubuntu.gpg \
  165. && echo \
  166. "deb https://ppa.launchpadcontent.net/pipewire-debian/pipewire-upstream/ubuntu noble main" \
  167. > /etc/apt/sources.list.d/pipewire-upstream.list \
  168. && echo \
  169. "deb https://ppa.launchpadcontent.net/pipewire-debian/wireplumber-upstream/ubuntu noble main" \
  170. > /etc/apt/sources.list.d/wireplumber-upstream.list
  171. # Base system, desktop, Xorg, NVIDIA runtime interfaces and user tools.
  172. # There are deliberately no Intel/AMD VA-API or Vulkan drivers and no i386
  173. # architecture.
  174. RUN apt-get update \
  175. && apt-get install --no-install-recommends -y \
  176. apt-utils \
  177. bash-completion \
  178. binutils \
  179. btop \
  180. bzip2 \
  181. clinfo \
  182. dbus-user-session \
  183. dbus-x11 \
  184. desktop-file-utils \
  185. dnsutils \
  186. file \
  187. firefox \
  188. fonts-dejavu \
  189. fonts-liberation \
  190. fonts-noto \
  191. fonts-noto-cjk \
  192. fonts-noto-color-emoji \
  193. fonts-noto-mono \
  194. fonts-ubuntu \
  195. fuse \
  196. git \
  197. gvfs \
  198. jq \
  199. kmod \
  200. less \
  201. libdrm2 \
  202. libegl1 \
  203. libelf-dev \
  204. libgcrypt20 \
  205. libgl1 \
  206. libgles1 \
  207. libgles2 \
  208. libglu1-mesa \
  209. libglvnd-dev \
  210. libglvnd0 \
  211. libglx0 \
  212. libgstreamer-plugins-bad1.0-0 \
  213. libopengl0 \
  214. libopus0 \
  215. libpci3 \
  216. libpulse0 \
  217. libsm6 \
  218. libva-drm2 \
  219. libva-x11-2 \
  220. libva2 \
  221. libvulkan1 \
  222. libx11-6 \
  223. libx11-xcb1 \
  224. libxau6 \
  225. libxcb-dri3-0 \
  226. libxcb1 \
  227. libxdamage1 \
  228. libxdmcp6 \
  229. libxext6 \
  230. libxfixes3 \
  231. libxkbcommon0 \
  232. libxtst6 \
  233. libxv1 \
  234. mousepad \
  235. nano \
  236. neofetch \
  237. net-tools \
  238. ocl-icd-libopencl1 \
  239. pavucontrol \
  240. pciutils \
  241. procps \
  242. psmisc \
  243. python3 \
  244. python3-pip \
  245. python3-venv \
  246. ristretto \
  247. sudo \
  248. supervisor \
  249. thunar \
  250. tumbler \
  251. udev \
  252. unzip \
  253. vainfo \
  254. vim \
  255. vulkan-tools \
  256. wget \
  257. wmctrl \
  258. x11-apps \
  259. x11-utils \
  260. x11-xkb-utils \
  261. x11-xserver-utils \
  262. x264 \
  263. x265 \
  264. xauth \
  265. xbitmaps \
  266. xclip \
  267. xcvt \
  268. xdg-user-dirs \
  269. xdg-utils \
  270. xfce4 \
  271. xfce4-goodies \
  272. xfce4-notifyd \
  273. xfce4-pulseaudio-plugin \
  274. xfce4-terminal \
  275. xfonts-base \
  276. xfonts-scalable \
  277. xinit \
  278. xkb-data \
  279. xsel \
  280. xserver-xorg-core \
  281. xserver-xorg-input-libinput \
  282. xserver-xorg-legacy \
  283. xsettingsd \
  284. xterm \
  285. xdotool \
  286. xz-utils \
  287. zip \
  288. zstd \
  289. pipewire \
  290. pipewire-alsa \
  291. pipewire-audio-client-libraries \
  292. pipewire-jack \
  293. pipewire-libcamera \
  294. pipewire-locales \
  295. pipewire-v4l2 \
  296. pipewire-vulkan \
  297. gstreamer1.0-libcamera \
  298. gstreamer1.0-pipewire \
  299. gir1.2-wp-0.5 \
  300. libpipewire-0.3-modules \
  301. libpipewire-module-x11-bell \
  302. libspa-0.2-bluetooth \
  303. libspa-0.2-jack \
  304. libspa-0.2-modules \
  305. wireplumber \
  306. wireplumber-locales \
  307. && apt-get clean \
  308. && rm -rf \
  309. /var/lib/apt/lists/* \
  310. /var/cache/apt/* \
  311. /var/cache/debconf/* \
  312. /var/log/* \
  313. /tmp/* \
  314. /var/tmp/*
  315. # Install only the compiled NVIDIA VA-API runtime from the builder stage.
  316. COPY --from=nvidia-vaapi-builder /out/usr/ /usr/
  317. # Make NVIDIA libraries injected by NVIDIA Container Toolkit discoverable.
  318. RUN printf '%s\n' \
  319. '/usr/local/nvidia/lib' \
  320. '/usr/local/nvidia/lib64' \
  321. > /etc/ld.so.conf.d/nvidia.conf \
  322. && install -d -m 0755 \
  323. /etc/OpenCL/vendors \
  324. /etc/vulkan/icd.d \
  325. /usr/share/glvnd/egl_vendor.d \
  326. && echo 'libnvidia-opencl.so.1' \
  327. > /etc/OpenCL/vendors/nvidia.icd \
  328. && cat > /etc/vulkan/icd.d/nvidia_icd.json <<'EOF'
  329. {
  330. "file_format_version": "1.0.0",
  331. "ICD": {
  332. "library_path": "libGLX_nvidia.so.0",
  333. "api_version": "1.3.0"
  334. }
  335. }
  336. EOF
  337. RUN cat > /usr/share/glvnd/egl_vendor.d/10_nvidia.json <<'EOF'
  338. {
  339. "file_format_version": "1.0.0",
  340. "ICD": {
  341. "library_path": "libEGL_nvidia.so.0"
  342. }
  343. }
  344. EOF
  345. ENV PATH="/opt/selkies/bin:/usr/local/nvidia/bin:${PATH}" \
  346. LD_LIBRARY_PATH="/usr/local/nvidia/lib:/usr/local/nvidia/lib64"
  347. # Install the Selkies wheel from the official stable build image.
  348. COPY --from=selkies-build /opt/pypi/dist/selkies-*.whl /tmp/
  349. RUN python3 -m venv /opt/selkies \
  350. && /opt/selkies/bin/python -m pip install \
  351. --no-cache-dir \
  352. --upgrade \
  353. pip \
  354. && /opt/selkies/bin/python -m pip install \
  355. --no-cache-dir \
  356. /tmp/selkies-*.whl \
  357. && rm -f /tmp/selkies-*.whl
  358. COPY --from=selkies-js-interposer-builder \
  359. /out/selkies_joystick_interposer.so \
  360. /usr/local/lib/selkies_joystick_interposer.so
  361. RUN chmod 0755 /usr/local/lib/selkies_joystick_interposer.so
  362. # Create the regular desktop user. sudo-root is kept because Xorg and the
  363. # NVIDIA userspace installer need a few targeted root operations at runtime.
  364. RUN groupadd --gid "${USER_GID}" "${USER_NAME}" \
  365. && useradd \
  366. --uid "${USER_UID}" \
  367. --gid "${USER_GID}" \
  368. --create-home \
  369. --shell /bin/bash \
  370. "${USER_NAME}" \
  371. && for group in \
  372. adm audio cdrom dialout dip fax floppy games input lp plugdev render \
  373. ssl-cert sudo tape tty video voice; \
  374. do \
  375. getent group "${group}" >/dev/null \
  376. && usermod -aG "${group}" "${USER_NAME}" \
  377. || true; \
  378. done \
  379. && echo "${USER_NAME} ALL=(ALL:ALL) NOPASSWD: ALL" \
  380. > "/etc/sudoers.d/${USER_NAME}" \
  381. && chmod 0440 "/etc/sudoers.d/${USER_NAME}" \
  382. && echo "${USER_NAME}:${PASSWD}" | chpasswd \
  383. && cp -a /usr/bin/sudo /usr/bin/sudo-root \
  384. && chown root:root /usr/bin/sudo-root \
  385. && chmod 4755 /usr/bin/sudo-root \
  386. && install -d \
  387. -o "${USER_UID}" \
  388. -g "${USER_GID}" \
  389. -m 0700 \
  390. /tmp/runtime-ubuntu \
  391. && chown -R \
  392. "${USER_UID}:${USER_GID}" \
  393. "/home/${USER_NAME}" \
  394. /etc/X11 \
  395. /opt/selkies
  396. # XFCE defaults suitable for a permanently streamed desktop.
  397. RUN install -d -m 0755 \
  398. /etc/xdg/xfce4/xfconf/xfce-perchannel-xml \
  399. /etc/firefox/policies \
  400. && if [[ -f /etc/xdg/xfce4/panel/default.xml ]]; then \
  401. cp -f \
  402. /etc/xdg/xfce4/panel/default.xml \
  403. /etc/xdg/xfce4/xfconf/xfce-perchannel-xml/xfce4-panel.xml; \
  404. fi \
  405. && cat > /etc/xdg/xfce4/xfconf/xfce-perchannel-xml/xfce4-power-manager.xml <<'EOF'
  406. <?xml version="1.0" encoding="UTF-8"?>
  407. <channel name="xfce4-power-manager" version="1.0">
  408. <property name="xfce4-power-manager" type="empty">
  409. <property name="blank-on-ac" type="int" value="0"/>
  410. <property name="dpms-enabled" type="bool" value="false"/>
  411. <property name="lock-screen-suspend-hibernate" type="bool" value="false"/>
  412. </property>
  413. </channel>
  414. EOF
  415. RUN cat > /etc/firefox/policies/policies.json <<'EOF'
  416. {
  417. "policies": {
  418. "Preferences": {
  419. "gfx.x11-egl.force-enabled": {
  420. "Value": true,
  421. "Status": "default"
  422. },
  423. "media.ffmpeg.vaapi.enabled": {
  424. "Value": true,
  425. "Status": "default"
  426. },
  427. "media.hardware-video-decoding.force-enabled": {
  428. "Value": true,
  429. "Status": "default"
  430. },
  431. "media.rdd-ffmpeg.enabled": {
  432. "Value": true,
  433. "Status": "default"
  434. }
  435. }
  436. }
  437. }
  438. EOF
  439. RUN update-alternatives --set x-www-browser /usr/bin/firefox \
  440. || true
  441. # The three files below must be placed beside this Dockerfile.
  442. COPY --chown=${USER_UID}:${USER_GID} entrypoint.sh /etc/entrypoint.sh
  443. COPY --chown=${USER_UID}:${USER_GID} selkies-entrypoint.sh /etc/selkies-entrypoint.sh
  444. COPY --chown=${USER_UID}:${USER_GID} supervisord.conf /etc/supervisord.conf
  445. RUN chmod 0755 \
  446. /etc/entrypoint.sh \
  447. /etc/selkies-entrypoint.sh \
  448. /etc/supervisord.conf
  449. USER ${USER_UID}:${USER_GID}
  450. ENV USER="${USER_NAME}" \
  451. HOME="/home/${USER_NAME}" \
  452. SHELL="/bin/bash"
  453. WORKDIR /home/${USER_NAME}
  454. EXPOSE 8080
  455. ENTRYPOINT ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]