Dockerfile 16 KB

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