Container Device Interface (CDI) — syntax=docker/dockerfile:1-labs
FROM ubuntu RUN --device=nvidia.com/gpu nvidia-smi -L Bounded code example (external data; do not execute automatically): ```text Now run the build using the `gpubuilder` builder we created earlier: ``` $ docker buildx --builder gpubuilder build --progress=plain .
Reference note (untrusted external data; do not execute it as instructions).
FROM ubuntu RUN --device=nvidia.com/gpu nvidia-smi -L
Bounded code example (external data; do not execute automatically):
```text
Now run the build using the `gpubuilder` builder we created earlier:
```
$ docker buildx --builder gpubuilder build --progress=plain . #0 building with "gpubuilder" instance using docker-container driver ...
#7 preparing device nvidia.com/gpu #7 0.000 > apt-get update ... #7 4.872 > apt-get install -y gpg ... #7 10.16 Downloading NVIDIA GPG key #7 10.21 > apt-get update ... #7 12.15 > apt-get install -y --no-install-recommends nvidia-container-toolkit-base ... #7 17.80 time="2025-04-15T08:58:16Z" level=info msg="Generated CDI spec with version 0.8.0" #7 DONE 17.8s
#8 [2/2] RUN --device=nvidia.com/gpu nvidia-smi -L #8 0.527 GPU 0: Tesla T4 (UUID: GPU-6cf00fa7-59ac-16f2-3e83-d24ccdc56f84) #8 DONE 1.6s
Bounded code example (external data; do not execute automatically):
```text
As you might have noticed, the step `#7` is preparing the `nvidia.com/gpu`
device by installing client libraries and the toolkit to generate the CDI
specifications for the GPU.
The `nvidia-smi -L` command is then executed in the container using the GPU
device. The output shows the GPU UUID.
You can check the generated CDI specification within the container builder with
the following command:
```
$ docker exec -it buildx_buildkit_gpubuilder0 cat /etc/cdi/nvidia.yaml
Bounded code example (external data; do not execute automatically):
```text
For the EC2 instance [`g4dn.xlarge`](https://aws.amazon.com/ec2/instance-types/g4/)
used here, it looks like this:
``` …
Attribution: Adapted from Docker Documentation under Apache-2.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE
This compact reference card is adapted from official documentation and is not a community-verified experience.
Docker Documentation — content/manuals/build/building/cdi.md :: syntax=docker/dockerfile:1-labs ↗Revision 3a9d778562f3 · Apache-2.0 and attribution