brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: docker run with gpus all gives a container your NVIDIA card

Docker
~/tips/tip-docker-run-gpus-all

docker run --rm --gpus all ubuntu nvidia-smi

Pass an NVIDIA GPU into a container for transcoding or machine learning.

Jellyfin transcoding, Immich face detection and local AI models all run much faster on a GPU. With the NVIDIA Container Toolkit installed on the host, one flag hands the card to a container.

docker run --rm --gpus all ubuntu nvidia-smi

If that prints the familiar nvidia-smi table, the toolkit works and containers can see the GPU. The toolkit injects the driver libraries, so the image does not need its own driver. For a single card out of several, name it:

docker run -d --gpus '"device=0"' example/app:1.0

In Compose the same thing goes under deploy.resources.reservations.devices with driver: nvidia and capabilities: [gpu].

The flag alone does nothing without the toolkit. Docker then fails with an error that it could not select a device driver with capabilities gpu. I would install the toolkit from NVIDIA’s own repository and run nvidia-ctk runtime configure as their guide describes, then restart Docker. On Unraid the Nvidia Driver plugin takes care of this part. Intel and AMD GPUs do not use this flag; for those you pass /dev/dri with --device.

Further reading: Resource constraints: GPU, NVIDIA Container Toolkit install guide

More Docker tips ONBUILD RUN /usr/local/bin/python-build --dir /app/src SHELL ["/bin/bash", "-c"] docker commit <container> myname/testimage:version3 docker import /path/to/exampleimage.tgz docker compose events All Docker tips (192) All topics

Link