Dockerfile 15 KB

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