From 28c19ed1b23939ea5eb01a6c5a842352e5b860c2 Mon Sep 17 00:00:00 2001 From: "Josh.5" Date: Fri, 15 Mar 2024 04:52:32 +1300 Subject: [PATCH] Update docker compose templates to not rely on NVIDIA runtime Plenty of setups may have either nvidia container toolkit without the runtime wrapper, or no toolkit at all. These updated templates allow for all those cases while still providing support for NVIDIA GPUs. --- docs/compose-files/.env | 10 +--- docs/compose-files/docker-compose.default.yml | 16 +++++- .../docker-compose.privileged.yml | 52 ++++++++++++++++--- 3 files changed, 62 insertions(+), 16 deletions(-) diff --git a/docs/compose-files/.env b/docs/compose-files/.env index 25bd78b..c2a253d 100644 --- a/docs/compose-files/.env +++ b/docs/compose-files/.env @@ -10,13 +10,6 @@ TZ=Pacific/Auckland USER_LOCALES=en_US.UTF-8 UTF-8 DISPLAY=:55 SHM_SIZE=2G -## DOCKER_RUNTIME: -## Options: ['runc', 'nvidia'] -## Description: The name of an implementation of OCI Runtime Spec -## Available runtimes are listed when you run `docker info`. -## Your system may have other options available. As a simple rule, if you are -## using an NVIDIA GPU, set this to 'nvidia' for anything else, set this to 'runc'. -DOCKER_RUNTIME=runc ## HOME_DIR: ## Description: The path to the home directory on your host. Mounts to `/home/default` inside the container. HOME_DIR=/opt/container-data/steam-headless/home @@ -118,7 +111,8 @@ NVIDIA_DRIVER_CAPABILITIES=all ## Supported Modes: ['primary', 'secondary'] NVIDIA_VISIBLE_DEVICES=all ## NVIDIA_DRIVER_VERSION: -## Description: Specify a driver version to force installation. Requires DOCKER_RUNTIME to be 'runc'. +## Description: Specify a driver version to force installation. +## Not meant to be used if nvidia container toolkit is installed. ## Detect current host driver installed with `nvidia-smi 2> /dev/null | grep NVIDIA-SMI | cut -d ' ' -f3` ## Supported Modes: ['primary', 'secondary'] NVIDIA_DRIVER_VERSION= diff --git a/docs/compose-files/docker-compose.default.yml b/docs/compose-files/docker-compose.default.yml index 3a81397..c715020 100644 --- a/docs/compose-files/docker-compose.default.yml +++ b/docs/compose-files/docker-compose.default.yml @@ -1,9 +1,10 @@ --- +version: "3.9" + services: steam-headless: image: josh5/steam-headless:latest restart: unless-stopped - runtime: ${DOCKER_RUNTIME} shm_size: ${SHM_SIZE} ipc: host # Could also be set to 'shareable' ulimits: @@ -18,6 +19,17 @@ services: - seccomp:unconfined - apparmor:unconfined + # GPU PASSTHROUGH + deploy: + resources: + reservations: + # Enable support for NVIDIA GPUs. + # + # Ref: https://docs.docker.com/compose/gpu-support/#enabling-gpu-access-to-service-containers + devices: + - capabilities: [gpu] + device_ids: ["${NVIDIA_VISIBLE_DEVICES}"] + # NETWORK: network_mode: host hostname: ${NAME} @@ -65,7 +77,7 @@ services: - /dev/uinput # Add AMD/Intel HW accelerated video encoding/decoding devices [OPTIONAL]. #- /dev/dri - # Add NVIDIA HW accelerated devices [OPTIONAL - must be run with runc docker runtime. If you use the nvidia runtime, this is not needed]. + # Add NVIDIA HW accelerated devices [OPTIONAL - If you use the nvidia container toolkit, this is not needed]. #- /dev/nvidia0 #- /dev/nvidiactl #- /dev/nvidia-modeset diff --git a/docs/compose-files/docker-compose.privileged.yml b/docs/compose-files/docker-compose.privileged.yml index f9eca26..101db24 100644 --- a/docs/compose-files/docker-compose.privileged.yml +++ b/docs/compose-files/docker-compose.privileged.yml @@ -1,9 +1,10 @@ --- +version: "3.9" + services: steam-headless: image: josh5/steam-headless:latest restart: unless-stopped - runtime: ${DOCKER_RUNTIME} ## NOTE: This config uses privileged to access to host to be able to access the required devices privileged: true shm_size: ${SHM_SIZE} @@ -13,6 +14,17 @@ services: soft: 1024 hard: 524288 + # GPU PASSTHROUGH + deploy: + resources: + reservations: + # Enable support for NVIDIA GPUs. + # + # Ref: https://docs.docker.com/compose/gpu-support/#enabling-gpu-access-to-service-containers + devices: + - capabilities: [gpu] + device_ids: ["${NVIDIA_VISIBLE_DEVICES}"] + # NETWORK: ## NOTE: With this configuration, if we do not use the host network, then physical device input ## is not possible and your USB connected controllers will not work in steam games. @@ -23,20 +35,49 @@ services: # ENVIRONMENT: ## Read all config variables from the .env file - env_file: .env + environment: + # System + - TZ=${TZ} + - USER_LOCALES=${USER_LOCALES} + - DISPLAY=${DISPLAY} + # User + - PUID=${PUID} + - PGID=${PGID} + - UMASK=${UMASK} + - USER_PASSWORD=${USER_PASSWORD} + # Mode + - MODE=${MODE} + # Web UI + - WEB_UI_MODE=${WEB_UI_MODE} + - ENABLE_VNC_AUDIO=${ENABLE_VNC_AUDIO} + - PORT_NOVNC_WEB=${PORT_NOVNC_WEB} + - NEKO_NAT1TO1=${NEKO_NAT1TO1} + # Steam + - ENABLE_STEAM=${ENABLE_STEAM} + - STEAM_ARGS=${STEAM_ARGS} + # Sunshine + - ENABLE_SUNSHINE=${ENABLE_SUNSHINE} + - SUNSHINE_USER=${SUNSHINE_USER} + - SUNSHINE_PASS=${SUNSHINE_PASS} + # Xorg + - ENABLE_EVDEV_INPUTS=${ENABLE_EVDEV_INPUTS} + # Nvidia specific config + - NVIDIA_DRIVER_CAPABILITIES=${NVIDIA_DRIVER_CAPABILITIES} + - NVIDIA_VISIBLE_DEVICES=${NVIDIA_VISIBLE_DEVICES} + - NVIDIA_DRIVER_VERSION=${NVIDIA_DRIVER_VERSION} # VOLUMES: volumes: # The location of your home directory. - - /opt/container-data/steam-headless/home/:/home/default/:rw + - ${HOME_DIR}/:/home/default/:rw # The location where all games should be installed. # This path needs to be set as a library path in Steam after logging in. # Otherwise, Steam will store games in the home directory above. - - /mnt/games/:/mnt/games/:rw + - ${GAMES_DIR}/:/mnt/games/:rw # The Xorg socket. This will be shared with other containers so they can access the X server. - # Select only one option: + # Select only one option or leave commented out to not share the Xorg socket with any other Docker containers. # Option #1) Start a X server in the container to share with any other containers. #- /opt/container-data/steam-headless/.X11-unix/:/tmp/.X11-unix/:rw # Option #2) Use an existing X server running on the host. @@ -48,4 +89,3 @@ services: # Input devices used for mouse and joypad support inside the container. - /dev/input/:/dev/input/:ro -