Dockerfile 16 KB

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