Dockerfile 16 KB

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