Dockerfile 16 KB

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