Docker CDI: expose GPUs and other devices to a BuildKit build
Answer: The Container Device Interface (CDI) is a specification for exposing devices such as GPUs to containers, including during a Docker or BuildKit build.
What CDI provides
CDI standardizes how devices, including GPUs, FPGAs, and other accelerators, are exposed to containers, so hardware setup is more consistent and secure.
Besides giving the container access to the device node, a CDI spec can add environment variables, host mounts such as shared objects, and executable hooks.
A compatible environment needs Docker v27 or later with CDI configured, and Buildx v0.22 or later.
Device specs are JSON or YAML files in /etc/cdi, /var/run/cdi, or /etc/buildkit/cdi.
Using a device in a build
A simple spec can inject an environment variable. The example foo.yaml uses cdiVersion 0.6.0, kind vendor1.com/device, and a device named foo whose containerEdits set FOO=injected. docker buildx inspect should then list that vendor as a detected device.
A Dockerfile can request it with the labs frontend and RUN --device=vendor1.com/device. A build that requests a device that has not been allowed fails with a message that the device is requested by the build but not allowed.
You can allow it with the --allow flag on docker buildx build, or set the org.mobyproject.buildkit.device.autoallow annotation on the spec and pass --allow device.
For GPUs, a docker-container builder can be created so that a GPU request is automatically added if the host has a GPU. The example names the builder gpubuilder and uses the moby/buildkit:buildx-stable-1-gpu image. nvidia.com/gpu vendor is detected as a device in the builder.
A Dockerfile can then run nvidia-smi with RUN --device=nvidia.com/gpu, after BuildKit prepares that device.
See also
Claims
- id: C1 claim: CDI standardizes how devices such as GPUs are exposed to containers. source: S1 evidence: "standardize how devices (like GPUs, FPGAs, and"
- id: C2 claim: A compatible setup needs Docker v27 or later and Buildx v0.22 or later. source: S2 evidence: "having Docker v27+ installed"
- id: C3 claim: A requested device is not used until it is allowed, for example with --allow. source: S2 evidence: "requested by the build but not allowed"
Sources
- [S1] Container Device Interface (CDI). Docker, Inc.. https://docs.docker.com/build/building/cdi/ . License: Apache License 2.0. Accessed 2026-11-27.
- [S2] Container Device Interface (CDI) (source). Docker, Inc.. https://raw.githubusercontent.com/docker/docs/main/content/manuals/build/building/cdi.md . License: Apache License 2.0. Accessed 2026-11-27.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Docker, Inc., Container Device Interface (CDI); Docker, Inc., Container Device Interface (CDI) (source). Apache-2.0 (https://raw.githubusercontent.com/docker/docs/main/LICENSE). Copyright Docker, Inc. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Docker, Inc., Container Device Interface (CDI); Docker, Inc., Container Device Interface (CDI) (source). Apache-2.0 (https://raw.githubusercontent.com/docker/docs/main/LICENSE). Copyright Docker, Inc.
Cite this
iinventedlight. 2026. "Docker CDI: expose GPUs and other devices to a BuildKit build." iinventedlight Library, iil:note:yxc8xtk3, version of 2026-11-27. https://iinventedlight.com/library/notes/docker-build-cdi/. License: CC-BY-4.0.
@misc{iil_note_yxc8xtk3,
author = {{iinventedlight}},
title = {{Docker CDI: expose GPUs and other devices to a BuildKit build}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-27},
url = {https://iinventedlight.com/library/notes/docker-build-cdi/},
note = {Permanent ID iil:note:yxc8xtk3. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- docker-build-cdi.schema.json (schema; CC-BY-4.0)
- docker-build-cdi.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/docker-build-cdi.md.