Dockerfile 15 KB

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