Skip to content

Conversation

crazy-max
Copy link
Member

relates to #3295 (comment)

When generating the CDI spec during build for a container builder created on WSL it fails with:

#7 11.40 time="2025-07-18T02:55:21Z" level=warning msg="Could not locate libdxcore.so: pattern libdxcore.so not found"

It seems requesting GPU on container builder creation introduced in #3063 is not enough as some libraries are missing on WSL.

To fix this issue we can mount the WSL libraries in the container if docker context is local.

$ docker buildx create --name wsltest --bootstrap --driver-opt "image=crazymax/buildkit:v0.23.2-ubuntu-nvidia" --buildkitd-flags "--debug"
#1 [internal] booting buildkit
#1 pulling image crazymax/buildkit:v0.23.2-ubuntu-nvidia
#1 pulling image crazymax/buildkit:v0.23.2-ubuntu-nvidia 0.9s done
#1 creating container buildx_buildkit_wsltest0
#1 creating container buildx_buildkit_wsltest0 1.7s done
#1 DONE 2.6s
wsltest
$ docker inspect buildx_buildkit_wsltest0
...
        "Mounts": [
            {
                "Type": "volume",
                "Name": "buildx_buildkit_wsltest0_state",
                "Source": "/var/lib/docker/volumes/buildx_buildkit_wsltest0_state/_data",
                "Destination": "/var/lib/buildkit",
                "Driver": "local",
                "Mode": "z",
                "RW": true,
                "Propagation": ""
            },
            {
                "Type": "bind",
                "Source": "/run/desktop/mnt/host/wsl/docker-desktop-bind-mounts/Ubuntu/f969f076ad437ac0162d56bf356c2a910d8ddd313a6ac1d90246b6b64d06d59a",
                "Destination": "/usr/lib/wsl",
                "Mode": "",
                "RW": false,
                "Propagation": "rprivate"
            }
        ],
...
# syntax=docker/dockerfile:1.17-labs
FROM ubuntu
RUN --device=nvidia.com/gpu nvidia-smi -L
$ docker buildx --builder wsltest build --progress=plain .
#0 building with "wsltest" instance using docker-container driver

#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 128B done
#1 DONE 0.1s

#2 resolve image config for docker-image://docker.io/docker/dockerfile:1.17-labs
#2 ...

#3 [auth] docker/dockerfile:pull token for registry-1.docker.io
#3 DONE 0.0s

#2 resolve image config for docker-image://docker.io/docker/dockerfile:1.17-labs
#2 DONE 1.3s

#4 docker-image://docker.io/docker/dockerfile:1.17-labs@sha256:9187104f31e3a002a8a6a3209ea1f937fb7486c093cbbde1e14b0fa0d7e4f1b5
#4 resolve docker.io/docker/dockerfile:1.17-labs@sha256:9187104f31e3a002a8a6a3209ea1f937fb7486c093cbbde1e14b0fa0d7e4f1b5 0.0s done
#4 sha256:a8987824096eac360499af15e51f5ecbaa6120cae7d3fa32cfddb6984d449c0d 0B / 14.09MB 0.2s
#4 sha256:a8987824096eac360499af15e51f5ecbaa6120cae7d3fa32cfddb6984d449c0d 7.34MB / 14.09MB 0.3s
#4 sha256:a8987824096eac360499af15e51f5ecbaa6120cae7d3fa32cfddb6984d449c0d 14.09MB / 14.09MB 0.5s
#4 sha256:a8987824096eac360499af15e51f5ecbaa6120cae7d3fa32cfddb6984d449c0d 14.09MB / 14.09MB 0.5s done
#4 extracting sha256:a8987824096eac360499af15e51f5ecbaa6120cae7d3fa32cfddb6984d449c0d 0.1s done
#4 DONE 0.6s

#5 [internal] load metadata for docker.io/library/ubuntu:latest
#5 ...

#6 [auth] library/ubuntu:pull token for registry-1.docker.io
#6 DONE 0.0s

#5 [internal] load metadata for docker.io/library/ubuntu:latest
#5 DONE 0.8s

#7 [internal] load .dockerignore
#7 transferring context: 2B done
#7 DONE 0.0s

#8 [1/2] FROM docker.io/library/ubuntu:latest@sha256:c4570d2f4665d5d118ae29fb494dee4f8db8fcfaee0e37a2e19b827f399070d3
#8 resolve docker.io/library/ubuntu:latest@sha256:c4570d2f4665d5d118ae29fb494dee4f8db8fcfaee0e37a2e19b827f399070d3 0.0s done
#8 sha256:32f112e3802cadcab3543160f4d2aa607b3cc1c62140d57b4f5441384f40e927 0B / 29.72MB 0.2s
#8 sha256:32f112e3802cadcab3543160f4d2aa607b3cc1c62140d57b4f5441384f40e927 9.44MB / 29.72MB 0.3s
#8 sha256:32f112e3802cadcab3543160f4d2aa607b3cc1c62140d57b4f5441384f40e927 18.87MB / 29.72MB 0.5s
#8 sha256:32f112e3802cadcab3543160f4d2aa607b3cc1c62140d57b4f5441384f40e927 28.31MB / 29.72MB 0.6s
#8 sha256:32f112e3802cadcab3543160f4d2aa607b3cc1c62140d57b4f5441384f40e927 29.72MB / 29.72MB 0.7s done
#8 extracting sha256:32f112e3802cadcab3543160f4d2aa607b3cc1c62140d57b4f5441384f40e927
#8 extracting sha256:32f112e3802cadcab3543160f4d2aa607b3cc1c62140d57b4f5441384f40e927 0.7s done
#8 DONE 1.5s

#9 preparing device nvidia.com/gpu
#9 0.001 > /usr/bin/nvidia-smi -L
#9 0.042 GPU 0: NVIDIA GeForce RTX 3060 Ti (UUID: GPU-63109a83-ae03-3291-b519-c133b6caf78e)
#9 0.051 > apt-get update
#9 0.169 Get:1 http://archive.ubuntu.com/ubuntu noble InRelease [256 kB]
#9 0.246 Get:2 http://archive.ubuntu.com/ubuntu noble-updates InRelease [126 kB]
#9 0.265 Get:3 http://archive.ubuntu.com/ubuntu noble-backports InRelease [126 kB]
#9 0.296 Get:4 http://security.ubuntu.com/ubuntu noble-security InRelease [126 kB]
#9 0.311 Get:5 http://archive.ubuntu.com/ubuntu noble/main amd64 Packages [1808 kB]
#9 0.389 Get:6 http://archive.ubuntu.com/ubuntu noble/restricted amd64 Packages [117 kB]
#9 0.418 Get:7 http://archive.ubuntu.com/ubuntu noble/universe amd64 Packages [19.3 MB]
#9 0.736 Get:8 http://archive.ubuntu.com/ubuntu noble/multiverse amd64 Packages [331 kB]
#9 0.739 Get:9 http://archive.ubuntu.com/ubuntu noble-updates/universe amd64 Packages [1443 kB]
#9 0.763 Get:10 http://archive.ubuntu.com/ubuntu noble-updates/multiverse amd64 Packages [45.2 kB]
#9 0.764 Get:11 http://archive.ubuntu.com/ubuntu noble-updates/restricted amd64 Packages [1942 kB]
#9 0.796 Get:12 http://archive.ubuntu.com/ubuntu noble-updates/main amd64 Packages [1608 kB]
#9 0.813 Get:13 http://security.ubuntu.com/ubuntu noble-security/restricted amd64 Packages [1820 kB]
#9 0.821 Get:14 http://archive.ubuntu.com/ubuntu noble-backports/universe amd64 Packages [33.0 kB]
#9 0.822 Get:15 http://archive.ubuntu.com/ubuntu noble-backports/main amd64 Packages [48.8 kB]
#9 1.399 Get:16 http://security.ubuntu.com/ubuntu noble-security/universe amd64 Packages [1128 kB]
#9 1.446 Get:17 http://security.ubuntu.com/ubuntu noble-security/main amd64 Packages [1270 kB]
#9 1.512 Get:18 http://security.ubuntu.com/ubuntu noble-security/multiverse amd64 Packages [23.0 kB]
#9 1.556 Fetched 31.6 MB in 1s (21.6 MB/s)
#9 1.556 Reading package lists...
#9 2.198 > apt-get install -y gpg
#9 2.204 Reading package lists...
#9 2.816 Building dependency tree...
#9 2.968 Reading state information...
#9 3.114 The following additional packages will be installed:
#9 3.115   dirmngr gpg-agent gpgconf gpgv libksba8 libreadline8t64 libsqlite3-0
#9 3.115   pinentry-curses readline-common
#9 3.115 Suggested packages:
#9 3.115   gnupg dbus-user-session libpam-systemd pinentry-gnome3 tor keyboxd scdaemon
#9 3.115   pinentry-doc readline-doc
#9 3.146 The following NEW packages will be installed:
#9 3.147   dirmngr gpg gpg-agent gpgconf libksba8 libreadline8t64 libsqlite3-0
#9 3.147   pinentry-curses readline-common
#9 3.148 The following packages will be upgraded:
#9 3.149   gpgv
#9 3.193 1 upgraded, 9 newly installed, 0 to remove and 13 not upgraded.
#9 3.193 Need to get 2444 kB of archives.
#9 3.193 After this operation, 5597 kB of additional disk space will be used.
#9 3.193 Get:1 http://archive.ubuntu.com/ubuntu noble-updates/main amd64 gpgv amd64 2.4.4-2ubuntu17.3 [158 kB]
#9 3.262 Get:2 http://archive.ubuntu.com/ubuntu noble/main amd64 readline-common all 8.2-4build1 [56.5 kB]
#9 3.266 Get:3 http://archive.ubuntu.com/ubuntu noble/main amd64 libreadline8t64 amd64 8.2-4build1 [153 kB]
#9 3.281 Get:4 http://archive.ubuntu.com/ubuntu noble-updates/main amd64 libsqlite3-0 amd64 3.45.1-1ubuntu2.3 [701 kB]
#9 3.315 Get:5 http://archive.ubuntu.com/ubuntu noble-updates/main amd64 gpgconf amd64 2.4.4-2ubuntu17.3 [104 kB]
#9 3.317 Get:6 http://archive.ubuntu.com/ubuntu noble/main amd64 libksba8 amd64 1.6.6-1build1 [122 kB]
#9 3.323 Get:7 http://archive.ubuntu.com/ubuntu noble-updates/main amd64 dirmngr amd64 2.4.4-2ubuntu17.3 [323 kB]
#9 3.329 Get:8 http://archive.ubuntu.com/ubuntu noble-updates/main amd64 gpg amd64 2.4.4-2ubuntu17.3 [565 kB]
#9 3.352 Get:9 http://archive.ubuntu.com/ubuntu noble/main amd64 pinentry-curses amd64 1.2.1-3ubuntu5 [35.2 kB]
#9 3.352 Get:10 http://archive.ubuntu.com/ubuntu noble-updates/main amd64 gpg-agent amd64 2.4.4-2ubuntu17.3 [227 kB]
#9 3.490 debconf: delaying package configuration, since apt-utils is not installed
#9 3.530 Fetched 2444 kB in 0s (12.0 MB/s)
(Reading database ... 8613 files and directories currently installed.)
#9 3.580 Preparing to unpack .../gpgv_2.4.4-2ubuntu17.3_amd64.deb ...
#9 3.596 Unpacking gpgv (2.4.4-2ubuntu17.3) over (2.4.4-2ubuntu17.2) ...
#9 3.661 Setting up gpgv (2.4.4-2ubuntu17.3) ...
#9 3.708 Selecting previously unselected package readline-common.
(Reading database ... 8613 files and directories currently installed.)
#9 3.713 Preparing to unpack .../0-readline-common_8.2-4build1_all.deb ...
#9 3.718 Unpacking readline-common (8.2-4build1) ...
#9 3.770 Selecting previously unselected package libreadline8t64:amd64.
#9 3.772 Preparing to unpack .../1-libreadline8t64_8.2-4build1_amd64.deb ...
#9 3.786 Adding 'diversion of /lib/x86_64-linux-gnu/libhistory.so.8 to /lib/x86_64-linux-gnu/libhistory.so.8.usr-is-merged by libreadline8t64'
#9 3.794 Adding 'diversion of /lib/x86_64-linux-gnu/libhistory.so.8.2 to /lib/x86_64-linux-gnu/libhistory.so.8.2.usr-is-merged by libreadline8t64'
#9 3.800 Adding 'diversion of /lib/x86_64-linux-gnu/libreadline.so.8 to /lib/x86_64-linux-gnu/libreadline.so.8.usr-is-merged by libreadline8t64'
#9 3.805 Adding 'diversion of /lib/x86_64-linux-gnu/libreadline.so.8.2 to /lib/x86_64-linux-gnu/libreadline.so.8.2.usr-is-merged by libreadline8t64'
#9 3.809 Unpacking libreadline8t64:amd64 (8.2-4build1) ...
#9 3.856 Selecting previously unselected package libsqlite3-0:amd64.
#9 3.858 Preparing to unpack .../2-libsqlite3-0_3.45.1-1ubuntu2.3_amd64.deb ...
#9 3.863 Unpacking libsqlite3-0:amd64 (3.45.1-1ubuntu2.3) ...
#9 3.903 Selecting previously unselected package gpgconf.
#9 3.904 Preparing to unpack .../3-gpgconf_2.4.4-2ubuntu17.3_amd64.deb ...
#9 3.909 Unpacking gpgconf (2.4.4-2ubuntu17.3) ...
#9 3.954 Selecting previously unselected package libksba8:amd64.
#9 3.955 Preparing to unpack .../4-libksba8_1.6.6-1build1_amd64.deb ...
#9 3.961 Unpacking libksba8:amd64 (1.6.6-1build1) ...
#9 4.006 Selecting previously unselected package dirmngr.
#9 4.007 Preparing to unpack .../5-dirmngr_2.4.4-2ubuntu17.3_amd64.deb ...
#9 4.022 Unpacking dirmngr (2.4.4-2ubuntu17.3) ...
#9 4.062 Selecting previously unselected package gpg.
#9 4.063 Preparing to unpack .../6-gpg_2.4.4-2ubuntu17.3_amd64.deb ...
#9 4.068 Unpacking gpg (2.4.4-2ubuntu17.3) ...
#9 4.113 Selecting previously unselected package pinentry-curses.
#9 4.114 Preparing to unpack .../7-pinentry-curses_1.2.1-3ubuntu5_amd64.deb ...
#9 4.119 Unpacking pinentry-curses (1.2.1-3ubuntu5) ...
#9 4.161 Selecting previously unselected package gpg-agent.
#9 4.162 Preparing to unpack .../8-gpg-agent_2.4.4-2ubuntu17.3_amd64.deb ...
#9 4.167 Unpacking gpg-agent (2.4.4-2ubuntu17.3) ...
#9 4.212 Setting up libksba8:amd64 (1.6.6-1build1) ...
#9 4.228 Setting up pinentry-curses (1.2.1-3ubuntu5) ...
#9 4.255 Setting up libsqlite3-0:amd64 (3.45.1-1ubuntu2.3) ...
#9 4.271 Setting up readline-common (8.2-4build1) ...
#9 4.290 Setting up libreadline8t64:amd64 (8.2-4build1) ...
#9 4.306 Setting up gpgconf (2.4.4-2ubuntu17.3) ...
#9 4.321 Setting up gpg (2.4.4-2ubuntu17.3) ...
#9 4.336 Setting up gpg-agent (2.4.4-2ubuntu17.3) ...
#9 4.693 Setting up dirmngr (2.4.4-2ubuntu17.3) ...
#9 4.796 Processing triggers for libc-bin (2.39-0ubuntu8.4) ...
#9 4.860 Downloading NVIDIA GPG key
#9 4.912 > apt-get update
#9 4.972 Hit:1 http://archive.ubuntu.com/ubuntu noble InRelease
#9 4.981 Hit:2 http://archive.ubuntu.com/ubuntu noble-updates InRelease
#9 4.996 Hit:3 http://archive.ubuntu.com/ubuntu noble-backports InRelease
#9 4.996 Get:4 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64  InRelease [1581 B]
#9 5.128 Hit:5 http://security.ubuntu.com/ubuntu noble-security InRelease
#9 5.155 Get:6 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64  Packages [737 kB]
#9 5.256 Fetched 739 kB in 0s (2257 kB/s)
#9 5.256 Reading package lists...
#9 5.899 > apt-get install -y --no-install-recommends nvidia-container-toolkit-base
#9 5.903 Reading package lists...
#9 6.512 Building dependency tree...
#9 6.683 Reading state information...
#9 6.867 The following NEW packages will be installed:
#9 6.868   nvidia-container-toolkit-base
#9 7.533 0 upgraded, 1 newly installed, 0 to remove and 13 not upgraded.
#9 7.533 Need to get 3797 kB of archives.
#9 7.533 After this operation, 20.7 MB of additional disk space will be used.
#9 7.533 Get:1 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64  nvidia-container-toolkit-base 1.17.8-1 [3797 kB]
#9 7.732 debconf: delaying package configuration, since apt-utils is not installed
#9 7.753 Fetched 3797 kB in 1s (4977 kB/s)
#9 7.775 Selecting previously unselected package nvidia-container-toolkit-base.
(Reading database ... 8732 files and directories currently installed.)
#9 7.779 Preparing to unpack .../nvidia-container-toolkit-base_1.17.8-1_amd64.deb ...
#9 7.785 Unpacking nvidia-container-toolkit-base (1.17.8-1) ...
#9 8.028 Setting up nvidia-container-toolkit-base (1.17.8-1) ...
#9 8.078 time="2025-07-18T11:21:09Z" level=info msg="Using /usr/lib/x86_64-linux-gnu/libnvidia-ml.so.1"
#9 8.099 time="2025-07-18T11:21:09Z" level=info msg="Auto-detected mode as 'wsl'"
#9 8.099 time="2025-07-18T11:21:09Z" level=info msg="Selecting /dev/dxg as /dev/dxg"
#9 8.100 time="2025-07-18T11:21:09Z" level=info msg="Using WSL driver store paths: [/usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f]"
#9 8.100 time="2025-07-18T11:21:09Z" level=info msg="Selecting /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libcuda.so.1.1 as /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libcuda.so.1.1"   
#9 8.101 time="2025-07-18T11:21:09Z" level=info msg="Selecting /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libcuda_loader.so as /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libcuda_loader.so"
#9 8.101 time="2025-07-18T11:21:09Z" level=info msg="Selecting /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libnvidia-ptxjitcompiler.so.1 as /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libnvidia-ptxjitcompiler.so.1"
#9 8.101 time="2025-07-18T11:21:09Z" level=info msg="Selecting /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libnvidia-ml.so.1 as /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libnvidia-ml.so.1"
#9 8.102 time="2025-07-18T11:21:09Z" level=info msg="Selecting /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libnvidia-ml_loader.so as /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libnvidia-ml_loader.so"
#9 8.102 time="2025-07-18T11:21:09Z" level=info msg="Selecting /usr/lib/wsl/lib/libdxcore.so as /usr/lib/wsl/lib/libdxcore.so"
#9 8.103 time="2025-07-18T11:21:09Z" level=info msg="Selecting /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libnvdxgdmal.so.1 as /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libnvdxgdmal.so.1"
#9 8.103 time="2025-07-18T11:21:09Z" level=info msg="Selecting /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/nvcubins.bin as /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/nvcubins.bin"
#9 8.104 time="2025-07-18T11:21:09Z" level=info msg="Selecting /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/nvidia-smi as /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/nvidia-smi"
#9 8.104 time="2025-07-18T11:21:09Z" level=info msg="Generated CDI spec with version 0.8.0"
#9 DONE 8.1s

#10 [2/2] RUN --device=nvidia.com/gpu nvidia-smi -L
#10 0.129 GPU 0: NVIDIA GeForce RTX 3060 Ti (UUID: GPU-63109a83-ae03-3291-b519-c133b6caf78e)
#10 DONE 0.6s

Inspecting the CDI spec we can see libdxcore.so is properly detected and mounted:

$ docker exec -it buildx_buildkit_wsltest0 cat /etc/cdi/nvidia.yaml
---
cdiVersion: 0.3.0
containerEdits:
  env:
  - NVIDIA_VISIBLE_DEVICES=void
  hooks:
  - args:
    - nvidia-cdi-hook
    - create-symlinks
    - --link
    - /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/nvidia-smi::/usr/bin/nvidia-smi
    env:
    - NVIDIA_CTK_DEBUG=false
    hookName: createContainer
    path: /usr/bin/nvidia-cdi-hook
  - args:
    - nvidia-cdi-hook
    - update-ldcache
    - --folder
    - /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f
    - --folder
    - /usr/lib/wsl/lib
    env:
    - NVIDIA_CTK_DEBUG=false
    hookName: createContainer
    path: /usr/bin/nvidia-cdi-hook
  mounts:
  - containerPath: /usr/lib/wsl/lib/libdxcore.so
    hostPath: /usr/lib/wsl/lib/libdxcore.so
    options:
    - ro
    - nosuid
    - nodev
    - bind
  - containerPath: /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libcuda.so.1.1
    hostPath: /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libcuda.so.1.1
    options:
    - ro
    - nosuid
    - nodev
    - bind
  - containerPath: /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libcuda_loader.so
    hostPath: /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libcuda_loader.so
    options:
    - ro
    - nosuid
    - nodev
    - bind
  - containerPath: /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libnvdxgdmal.so.1
    hostPath: /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libnvdxgdmal.so.1
    options:
    - ro
    - nosuid
    - nodev
    - bind
  - containerPath: /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libnvidia-ml.so.1
    hostPath: /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libnvidia-ml.so.1
    options:
    - ro
    - nosuid
    - nodev
    - bind
  - containerPath: /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libnvidia-ml_loader.so
    hostPath: /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libnvidia-ml_loader.so
    options:
    - ro
    - nosuid
    - nodev
    - bind
  - containerPath: /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libnvidia-ptxjitcompiler.so.1
    hostPath: /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libnvidia-ptxjitcompiler.so.1
    options:
    - ro
    - nosuid
    - nodev
    - bind
  - containerPath: /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/nvcubins.bin
    hostPath: /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/nvcubins.bin
    options:
    - ro
    - nosuid
    - nodev
    - bind
  - containerPath: /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/nvidia-smi
    hostPath: /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/nvidia-smi
    options:
    - ro
    - nosuid
    - nodev
    - bind
devices:
- containerEdits:
    deviceNodes:
    - path: /dev/dxg
  name: all
kind: nvidia.com/gpu

@crazy-max crazy-max added this to the v0.26.0 milestone Jul 18, 2025
@crazy-max crazy-max mentioned this pull request Jul 18, 2025
3 tasks
@crazy-max crazy-max requested a review from tonistiigi July 18, 2025 11:36
@crazy-max crazy-max marked this pull request as ready for review July 18, 2025 11:36
@crazy-max crazy-max mentioned this pull request Jul 18, 2025
3 tasks
@pechersky
Copy link

pechersky commented Jul 18, 2025

Following up on #3295 (comment).
Unfortunately, this didn't work on my machine. libdxcore is still missing in the container, but present on my host -- the wsltest builder didn't actually add a /usr/lib/wsl bind. I checked that I have pulled the most recent image of your buildkit image.

$ ls -ltahr /usr/lib/wsl/lib | grep libdx
-r-xr-xr-x 1 root root 920K Mar 31  2024 libdxcore.so
$ echo $WSL_DISTRO_NAME 
Ubuntu1
$ docker buildx create --name wsltest --bootstrap --driver-opt "image=crazymax/buildkit:v0.23.2-ubuntu-nvidia" --buildkitd-flags "--debug"
[+] Building 3.0s (1/1) FINISHED                                                                           
 => [internal] booting buildkit                                                                       3.0s
 => => pulling image crazymax/buildkit:v0.23.2-ubuntu-nvidia                                          0.7s
 => => creating container buildx_buildkit_wsltest0                                                    2.3s
wsltest
$ docker inspect buildx_buildkit_wsltest0 | grep wsl
        "Name": "/buildx_buildkit_wsltest0",
                    "Source": "buildx_buildkit_wsltest0_state",
                "Name": "buildx_buildkit_wsltest0_state",
                "Source": "/var/lib/docker/volumes/buildx_buildkit_wsltest0_state/_data",
                "desktop.docker.io/wsl-distro": "Ubuntu1",
$ docker buildx --builder wsltest build --progress=plain -f Dockerfile.test  .
#0 building with "wsltest" instance using docker-container driver

#1 [internal] load build definition from Dockerfile.test
#1 transferring dockerfile: 134B done
#1 DONE 0.0s

#2 resolve image config for docker-image://docker.io/docker/dockerfile:1.17-labs
#2 DONE 1.1s

#3 docker-image://docker.io/docker/dockerfile:1.17-labs@sha256:9187104f31e3a002a8a6a3209ea1f937fb7486c093cbbde1e14b0fa0d7e4f1b5
#3 resolve docker.io/docker/dockerfile:1.17-labs@sha256:9187104f31e3a002a8a6a3209ea1f937fb7486c093cbbde1e14b0fa0d7e4f1b5 0.0s done
#3 sha256:a8987824096eac360499af15e51f5ecbaa6120cae7d3fa32cfddb6984d449c0d 0B / 14.09MB 0.2s
#3 sha256:a8987824096eac360499af15e51f5ecbaa6120cae7d3fa32cfddb6984d449c0d 2.10MB / 14.09MB 0.3s
#3 sha256:a8987824096eac360499af15e51f5ecbaa6120cae7d3fa32cfddb6984d449c0d 4.19MB / 14.09MB 0.5s
#3 sha256:a8987824096eac360499af15e51f5ecbaa6120cae7d3fa32cfddb6984d449c0d 6.29MB / 14.09MB 0.6s
#3 sha256:a8987824096eac360499af15e51f5ecbaa6120cae7d3fa32cfddb6984d449c0d 8.39MB / 14.09MB 0.8s
#3 sha256:a8987824096eac360499af15e51f5ecbaa6120cae7d3fa32cfddb6984d449c0d 10.49MB / 14.09MB 0.9s
#3 sha256:a8987824096eac360499af15e51f5ecbaa6120cae7d3fa32cfddb6984d449c0d 12.58MB / 14.09MB 1.1s
#3 sha256:a8987824096eac360499af15e51f5ecbaa6120cae7d3fa32cfddb6984d449c0d 14.09MB / 14.09MB 1.1s done
#3 extracting sha256:a8987824096eac360499af15e51f5ecbaa6120cae7d3fa32cfddb6984d449c0d 0.1s done
#3 DONE 1.3s

#4 [internal] load metadata for docker.io/library/ubuntu:latest
#4 DONE 0.4s

#5 [internal] load .dockerignore
#5 transferring context: 114B done
#5 DONE 0.0s

#6 [1/2] FROM docker.io/library/ubuntu:latest@sha256:a08e551cb33850e4740772b38217fc1796a66da2506d312abe51acda354ff061
#6 resolve docker.io/library/ubuntu:latest@sha256:a08e551cb33850e4740772b38217fc1796a66da2506d312abe51acda354ff061 0.0s done
#6 DONE 0.0s

#6 [1/2] FROM docker.io/library/ubuntu:latest@sha256:a08e551cb33850e4740772b38217fc1796a66da2506d312abe51acda354ff061
#6 sha256:32f112e3802cadcab3543160f4d2aa607b3cc1c62140d57b4f5441384f40e927 1.05MB / 29.72MB 0.2s
#6 sha256:32f112e3802cadcab3543160f4d2aa607b3cc1c62140d57b4f5441384f40e927 3.15MB / 29.72MB 0.3s
#6 sha256:32f112e3802cadcab3543160f4d2aa607b3cc1c62140d57b4f5441384f40e927 6.29MB / 29.72MB 0.5s
#6 sha256:32f112e3802cadcab3543160f4d2aa607b3cc1c62140d57b4f5441384f40e927 8.39MB / 29.72MB 0.6s
#6 sha256:32f112e3802cadcab3543160f4d2aa607b3cc1c62140d57b4f5441384f40e927 10.49MB / 29.72MB 0.8s
#6 sha256:32f112e3802cadcab3543160f4d2aa607b3cc1c62140d57b4f5441384f40e927 13.63MB / 29.72MB 1.1s
#6 sha256:32f112e3802cadcab3543160f4d2aa607b3cc1c62140d57b4f5441384f40e927 16.78MB / 29.72MB 1.2s
#6 sha256:32f112e3802cadcab3543160f4d2aa607b3cc1c62140d57b4f5441384f40e927 19.92MB / 29.72MB 1.5s
#6 sha256:32f112e3802cadcab3543160f4d2aa607b3cc1c62140d57b4f5441384f40e927 22.02MB / 29.72MB 1.7s
#6 sha256:32f112e3802cadcab3543160f4d2aa607b3cc1c62140d57b4f5441384f40e927 24.12MB / 29.72MB 1.8s
#6 sha256:32f112e3802cadcab3543160f4d2aa607b3cc1c62140d57b4f5441384f40e927 26.21MB / 29.72MB 2.0s
#6 sha256:32f112e3802cadcab3543160f4d2aa607b3cc1c62140d57b4f5441384f40e927 28.31MB / 29.72MB 2.1s
#6 sha256:32f112e3802cadcab3543160f4d2aa607b3cc1c62140d57b4f5441384f40e927 29.72MB / 29.72MB 2.2s done
#6 extracting sha256:32f112e3802cadcab3543160f4d2aa607b3cc1c62140d57b4f5441384f40e927
#6 extracting sha256:32f112e3802cadcab3543160f4d2aa607b3cc1c62140d57b4f5441384f40e927 0.7s done
#6 DONE 2.9s

#7 preparing device nvidia.com/gpu
#7 0.002 > /usr/bin/nvidia-smi -L
#7 0.429 GPU 0: NVIDIA RTX A4500 Laptop GPU (UUID: GPU-ade25899-fff9-7c18-98dd-39132689d078)
#7 0.442 > apt-get update
#7 0.913 Get:1 http://security.ubuntu.com/ubuntu noble-security InRelease [126 kB]
#7 1.035 Get:2 http://archive.ubuntu.com/ubuntu noble InRelease [256 kB]
#7 1.129 Get:3 http://security.ubuntu.com/ubuntu noble-security/multiverse amd64 Packages [23.0 kB]
#7 1.175 Get:4 http://security.ubuntu.com/ubuntu noble-security/universe amd64 Packages [1128 kB]
#7 1.350 Get:5 http://security.ubuntu.com/ubuntu noble-security/main amd64 Packages [1270 kB]
#7 1.440 Get:6 http://security.ubuntu.com/ubuntu noble-security/restricted amd64 Packages [1820 kB]
#7 1.641 Get:7 http://archive.ubuntu.com/ubuntu noble-updates InRelease [126 kB]
#7 1.780 Get:8 http://archive.ubuntu.com/ubuntu noble-backports InRelease [126 kB]
#7 1.934 Get:9 http://archive.ubuntu.com/ubuntu noble/universe amd64 Packages [19.3 MB]
#7 3.663 Get:10 http://archive.ubuntu.com/ubuntu noble/main amd64 Packages [1808 kB]
#7 3.771 Get:11 http://archive.ubuntu.com/ubuntu noble/restricted amd64 Packages [117 kB]
#7 3.778 Get:12 http://archive.ubuntu.com/ubuntu noble/multiverse amd64 Packages [331 kB]
#7 3.801 Get:13 http://archive.ubuntu.com/ubuntu noble-updates/restricted amd64 Packages [1942 kB]
#7 3.927 Get:14 http://archive.ubuntu.com/ubuntu noble-updates/universe amd64 Packages [1443 kB]
#7 4.026 Get:15 http://archive.ubuntu.com/ubuntu noble-updates/multiverse amd64 Packages [45.2 kB]
#7 4.029 Get:16 http://archive.ubuntu.com/ubuntu noble-updates/main amd64 Packages [1608 kB]
#7 4.153 Get:17 http://archive.ubuntu.com/ubuntu noble-backports/main amd64 Packages [48.8 kB]
#7 4.161 Get:18 http://archive.ubuntu.com/ubuntu noble-backports/universe amd64 Packages [33.0 kB]
#7 4.503 Fetched 31.6 MB in 4s (7898 kB/s)
#7 4.503 Reading package lists...
#7 5.157 > apt-get install -y gpg
#7 5.161 Reading package lists...
#7 5.816 Building dependency tree...
#7 5.978 Reading state information...
#7 6.157 The following additional packages will be installed:
#7 6.158   pinentry-curses readline-common
#7 6.158 ibksba8 libreadline8t64 libsqlite3-0
#7 6.158   pinentry-curses readline-common
#7 6.159 Suggested packages:
#7 6.159   gnupg dbus-user-session libpam-systemd pinentry-gnome3 tor keyboxd scdaemon
#7 6.159   pinentry-doc readline-doc
#7 6.184 The following NEW packages will be installed:
#7 6.185   dirmngr gpg gpg-agent gpgconf libksba8 libreadline8t64 libsqlite3-0
#7 6.185   pinentry-curses readline-common
#7 6.185 The following packages will be upgraded:
#7 6.186   gpgv
#7 6.488 1 upgraded, 9 newly installed, 0 to remove and 13 not upgraded.
#7 6.488 Need to get 2444 kB of archives.
#7 6.488 After this operation, 5597 kB of additional disk space will be used.
#7 6.488 Get:1 http://archive.ubuntu.com/ubuntu noble-updates/main amd64 gpgv amd64 2.4.4-2ubuntu17.3 [158 kB]
#7 7.008 Get:2 http://archive.ubuntu.com/ubuntu noble/main amd64 readline-common all 8.2-4build1 [56.5 kB]
#7 7.035 Get:3 http://archive.ubuntu.com/ubuntu noble/main amd64 libreadline8t64 amd64 8.2-4build1 [153 kB]
#7 7.188 Get:4 http://archive.ubuntu.com/ubuntu noble-updates/main amd64 libsqlite3-0 amd64 3.45.1-1ubuntu2.3 [701 kB]
#7 7.384 Get:5 http://archive.ubuntu.com/ubuntu noble-updates/main amd64 gpgconf amd64 2.4.4-2ubuntu17.3 [104 kB]
#7 7.390 Get:6 http://archive.ubuntu.com/ubuntu noble/main amd64 libksba8 amd64 1.6.6-1build1 [122 kB]
#7 7.419 Get:7 http://archive.ubuntu.com/ubuntu noble-updates/main amd64 dirmngr amd64 2.4.4-2ubuntu17.3 [323 kB]
#7 7.467 Get:8 http://archive.ubuntu.com/ubuntu noble-updates/main amd64 gpg amd64 2.4.4-2ubuntu17.3 [565 kB]
#7 7.506 Get:9 http://archive.ubuntu.com/ubuntu noble/main amd64 pinentry-curses amd64 1.2.1-3ubuntu5 [35.2 kB]
#7 7.508 Get:10 http://archive.ubuntu.com/ubuntu noble-updates/main amd64 gpg-agent amd64 2.4.4-2ubuntu17.3 [227 kB]
#7 7.676 debconf: delaying package configuration, since apt-utils is not installed
#7 7.701 Fetched 2444 kB in 1s (1823 kB/s)
(Reading database ... 8613 files and directories currently installed.)
#7 7.748 Preparing to unpack .../gpgv_2.4.4-2ubuntu17.3_amd64.deb ...
#7 7.760 Unpacking gpgv (2.4.4-2ubuntu17.3) over (2.4.4-2ubuntu17.2) ...
#7 7.813 Setting up gpgv (2.4.4-2ubuntu17.3) ...
#7 7.850 Selecting previously unselected package readline-common.
(Reading database ... 8613 files and directories currently installed.)
#7 7.853 Preparing to unpack .../0-readline-common_8.2-4build1_all.deb ...
#7 7.857 Unpacking readline-common (8.2-4build1) ...
#7 7.899 Selecting previously unselected package libreadline8t64:amd64.
#7 7.900 Preparing to unpack .../1-libreadline8t64_8.2-4build1_amd64.deb ...
#7 7.911 Adding 'diversion of /lib/x86_64-linux-gnu/libhistory.so.8 to /lib/x86_64-linux-gnu/libhistory.so.8.usr-is-merged by libreadline8t64'
#7 7.918 Adding 'diversion of /lib/x86_64-linux-gnu/libhistory.so.8.2 to /lib/x86_64-linux-gnu/libhistory.so.8.2.usr-is-merged by libreadline8t64'
#7 7.923 Adding 'diversion of /lib/x86_64-linux-gnu/libreadline.so.8 to /lib/x86_64-linux-gnu/libreadline.so.8.usr-is-merged by libreadline8t64'
#7 7.928 Adding 'diversion of /lib/x86_64-linux-gnu/libreadline.so.8.2 to /lib/x86_64-linux-gnu/libreadline.so.8.2.usr-is-merged by libreadline8t64'
#7 7.932 Unpacking libreadline8t64:amd64 (8.2-4build1) ...
#7 7.970 Selecting previously unselected package libsqlite3-0:amd64.
#7 7.971 Preparing to unpack .../2-libsqlite3-0_3.45.1-1ubuntu2.3_amd64.deb ...
#7 7.976 Unpacking libsqlite3-0:amd64 (3.45.1-1ubuntu2.3) ...
#7 8.012 Selecting previously unselected package gpgconf.
#7 8.013 Preparing to unpack .../3-gpgconf_2.4.4-2ubuntu17.3_amd64.deb ...
#7 8.017 Unpacking gpgconf (2.4.4-2ubuntu17.3) ...
#7 8.054 Selecting previously unselected package libksba8:amd64.
#7 8.055 Preparing to unpack .../4-libksba8_1.6.6-1build1_amd64.deb ...
#7 8.062 Unpacking libksba8:amd64 (1.6.6-1build1) ...
#7 8.104 Selecting previously unselected package dirmngr.
#7 8.105 Preparing to unpack .../5-dirmngr_2.4.4-2ubuntu17.3_amd64.deb ...
#7 8.120 Unpacking dirmngr (2.4.4-2ubuntu17.3) ...
#7 8.155 Selecting previously unselected package gpg.
#7 8.156 Preparing to unpack .../6-gpg_2.4.4-2ubuntu17.3_amd64.deb ...
#7 8.160 Unpacking gpg (2.4.4-2ubuntu17.3) ...
#7 8.197 Selecting previously unselected package pinentry-curses.
#7 8.198 Preparing to unpack .../7-pinentry-curses_1.2.1-3ubuntu5_amd64.deb ...
#7 8.203 Unpacking pinentry-curses (1.2.1-3ubuntu5) ...
#7 8.236 Selecting previously unselected package gpg-agent.
#7 8.237 Preparing to unpack .../8-gpg-agent_2.4.4-2ubuntu17.3_amd64.deb ...
#7 8.241 Unpacking gpg-agent (2.4.4-2ubuntu17.3) ...
#7 8.275 Setting up libksba8:amd64 (1.6.6-1build1) ...
#7 8.288 Setting up pinentry-curses (1.2.1-3ubuntu5) ...
#7 8.311 Setting up libsqlite3-0:amd64 (3.45.1-1ubuntu2.3) ...
#7 8.323 Setting up readline-common (8.2-4build1) ...
#7 8.340 Setting up libreadline8t64:amd64 (8.2-4build1) ...
#7 8.351 Setting up gpgconf (2.4.4-2ubuntu17.3) ...
#7 8.364 Setting up gpg (2.4.4-2ubuntu17.3) ...
#7 8.376 Setting up gpg-agent (2.4.4-2ubuntu17.3) ...
#7 8.728 Setting up dirmngr (2.4.4-2ubuntu17.3) ...
#7 8.838 Processing triggers for libc-bin (2.39-0ubuntu8.4) ...
#7 8.955 Downloading NVIDIA GPG key
#7 9.335 > apt-get update
#7 9.640 Get:1 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64  InRelease [1581 B]
#7 9.672 Hit:2 http://archive.ubuntu.com/ubuntu noble InRelease
#7 9.709 Hit:3 http://security.ubuntu.com/ubuntu noble-security InRelease
#7 9.711 Get:4 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64  Packages [737 kB]
#7 9.775 Hit:5 http://archive.ubuntu.com/ubuntu noble-updates InRelease
#7 9.880 Hit:6 http://archive.ubuntu.com/ubuntu noble-backports InRelease
#7 9.918 Fetched 739 kB in 1s (1299 kB/s)
#7 9.918 Reading package lists...
#7 10.60 > apt-get install -y --no-install-recommends nvidia-container-toolkit-base
#7 10.60 Reading package lists...
#7 11.24 Building dependency tree...
#7 11.38 Reading state information...
#7 11.58 The following NEW packages will be installed:
#7 11.58   nvidia-container-toolkit-base
#7 11.89 0 upgraded, 1 newly installed, 0 to remove and 13 not upgraded.
#7 11.89 Need to get 3797 kB of archives.
#7 11.89 After this operation, 20.7 MB of additional disk space will be used.
#7 11.89 Get:1 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64  nvidia-container-toolkit-base 1.17.8-1 [3797 kB]
#7 12.33 debconf: delaying package configuration, since apt-utils is not installed
#7 12.35 Fetched 3797 kB in 1s (5760 kB/s)
#7 12.38 Selecting previously unselected package nvidia-container-toolkit-base.
(Reading database ... 8732 files and directories currently installed.)
#7 12.38 Preparing to unpack .../nvidia-container-toolkit-base_1.17.8-1_amd64.deb ...
#7 12.39 Unpacking nvidia-container-toolkit-base (1.17.8-1) ...
#7 12.66 Setting up nvidia-container-toolkit-base (1.17.8-1) ...
#7 12.70 time="2025-07-18T20:10:26Z" level=info msg="Using /usr/lib/x86_64-linux-gnu/libnvidia-ml.so.1"
#7 12.73 time="2025-07-18T20:10:26Z" level=info msg="Auto-detected mode as 'wsl'"
#7 12.73 time="2025-07-18T20:10:26Z" level=info msg="Selecting /dev/dxg as /dev/dxg"
#7 12.73 time="2025-07-18T20:10:26Z" level=info msg="Using WSL driver store paths: [/usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68 /usr/lib/wsl/drivers/iigd_dch.inf_amd64_b535843ef4c7897f]"
#7 12.73 time="2025-07-18T20:10:26Z" level=warning msg="Found multiple driver store paths: [/usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68 /usr/lib/wsl/drivers/iigd_dch.inf_amd64_b535843ef4c7897f]"
#7 12.73 time="2025-07-18T20:10:26Z" level=info msg="Selecting /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68/libcuda.so.1.1 as /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68/libcuda.so.1.1"
#7 12.73 time="2025-07-18T20:10:26Z" level=info msg="Selecting /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68/libcuda_loader.so as /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68/libcuda_loader.so"
#7 12.74 time="2025-07-18T20:10:26Z" level=info msg="Selecting /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68/libnvidia-ptxjitcompiler.so.1 as /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68/libnvidia-ptxjitcompiler.so.1"
#7 12.74 time="2025-07-18T20:10:26Z" level=info msg="Selecting /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68/libnvidia-ml.so.1 as /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68/libnvidia-ml.so.1"
#7 12.74 time="2025-07-18T20:10:26Z" level=info msg="Selecting /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68/libnvidia-ml_loader.so as /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68/libnvidia-ml_loader.so"
#7 12.74 time="2025-07-18T20:10:26Z" level=warning msg="Could not locate libdxcore.so: pattern libdxcore.so not found"
#7 12.74 time="2025-07-18T20:10:26Z" level=info msg="Selecting /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68/libnvdxgdmal.so.1 as /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68/libnvdxgdmal.so.1"
#7 12.74 time="2025-07-18T20:10:26Z" level=info msg="Selecting /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68/nvcubins.bin as /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68/nvcubins.bin"
#7 12.74 time="2025-07-18T20:10:26Z" level=info msg="Selecting /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68/nvidia-smi as /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68/nvidia-smi"
#7 12.74 time="2025-07-18T20:10:26Z" level=info msg="Generated CDI spec with version 0.8.0"
#7 DONE 12.7s

#8 [2/2] RUN --device=nvidia/gpu=all nvidia-smi -L
#8 0.158 Failed to initialize NVML: N/A
#8 ERROR: process "/bin/sh -c nvidia-smi -L" did not complete successfully: exit code: 3
------
 > [2/2] RUN --device=nvidia/gpu=all nvidia-smi -L:
0.158 Failed to initialize NVML: N/A
------
WARNING: No output specified with docker-container driver. Build result will only remain in the build cache. To push result image into registry use --push or to load image into docker use --load
Dockerfile.test:4
--------------------
   2 |     FROM ubuntu
   3 |     
   4 | >>> RUN --device=nvidia/gpu=all nvidia-smi -L
   5 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c nvidia-smi -L" did not complete successfully: exit code: 3

@crazy-max crazy-max modified the milestones: v0.26.0, v0.27.0 Jul 21, 2025
@crazy-max
Copy link
Member Author

crazy-max commented Jul 21, 2025

Unfortunately, this didn't work on my machine. libdxcore is still missing in the container, but present on my host -- the wsltest builder didn't actually add a /usr/lib/wsl bind. I checked that I have pulled the most recent image of your buildkit image.

Thanks for your feedback, can you show the output of docker info, docker context ls and docker context inspect?

@pechersky
Copy link

$ docker info
Client:
 Version:    28.1.1
 Context:    default
 Debug Mode: false
 Plugins:
  ai: Docker AI Agent - Ask Gordon (Docker Inc.)
    Version:  v1.1.7
    Path:     /usr/local/lib/docker/cli-plugins/docker-ai
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.23.0-desktop.1
    Path:     /usr/local/lib/docker/cli-plugins/docker-buildx
  cloud: Docker Cloud (Docker Inc.)
    Version:  v0.3.0
    Path:     /usr/local/lib/docker/cli-plugins/docker-cloud
  compose: Docker Compose (Docker Inc.)
    Version:  v2.35.1-desktop.1
    Path:     /usr/local/lib/docker/cli-plugins/docker-compose
  debug: Get a shell into any image or container (Docker Inc.)
    Version:  0.0.38
    Path:     /usr/local/lib/docker/cli-plugins/docker-debug
  desktop: Docker Desktop commands (Docker Inc.)
    Version:  v0.1.8
    Path:     /usr/local/lib/docker/cli-plugins/docker-desktop
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.2
    Path:     /usr/local/lib/docker/cli-plugins/docker-dev
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.27
    Path:     /usr/local/lib/docker/cli-plugins/docker-extension
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v1.4.0
    Path:     /usr/local/lib/docker/cli-plugins/docker-init
  mcp: Docker MCP Plugin (Docker Inc.)
    Version:  dev
    Path:     /usr/local/lib/docker/cli-plugins/docker-mcp
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     /usr/local/lib/docker/cli-plugins/docker-sbom
  scout: Docker Scout (Docker Inc.)
    Version:  v1.17.1
    Path:     /usr/local/lib/docker/cli-plugins/docker-scout
WARNING: Plugin "/usr/libexec/docker/cli-plugins/docker-app" is not valid: failed to fetch metadata: fork/exec /usr/libexec/docker/cli-plugins/docker-app: no such file or directory
WARNING: Plugin "/usr/local/lib/docker/cli-plugins/docker-feedback" is not valid: failed to fetch metadata: fork/exec /usr/local/lib/docker/cli-plugins/docker-feedback: no such file or directory
WARNING: Plugin "/usr/local/lib/docker/cli-plugins/docker-scan" is not valid: failed to fetch metadata: fork/exec /usr/local/lib/docker/cli-plugins/docker-scan: no such file or directory

Server:
 Containers: 34
  Running: 1
  Paused: 0
  Stopped: 33
 Images: 174
 Server Version: 28.1.1
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 CDI spec directories:
  /etc/cdi
  /var/run/cdi
 Swarm: inactive
 Runtimes: runc io.containerd.runc.v2 nvidia
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 05044ec0a9a75232cad458027ca83437aae3f4da
 runc version: v1.2.5-0-g59923ef
 init version: de40ad0
 Security Options:
  seccomp
   Profile: unconfined
 Kernel Version: 5.15.153.1-microsoft-standard-WSL2
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 20
 Total Memory: 31.19GiB
 Name: docker-desktop
 ID: c97ffdec-45d6-4718-b515-99bafc3201a4
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Labels:
  com.docker.desktop.address=unix:///var/run/docker-cli.sock
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  ::1/128
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: No blkio throttle.read_bps_device support
WARNING: No blkio throttle.write_bps_device support
WARNING: No blkio throttle.read_iops_device support
WARNING: No blkio throttle.write_iops_device support
WARNING: DOCKER_INSECURE_NO_IPTABLES_RAW is set
WARNING: daemon is not using the default seccomp profile
$ docker context ls
NAME            DESCRIPTION                               DOCKER ENDPOINT                             ERROR
default *       Current DOCKER_HOST based configuration   unix:///var/run/docker.sock                 
desktop-linux   Docker Desktop                            npipe:////./pipe/dockerDesktopLinuxEngine   
$ docker context inspect
[
    {
        "Name": "default",
        "Metadata": {},
        "Endpoints": {
            "docker": {
                "Host": "unix:///var/run/docker.sock",
                "SkipTLSVerify": false
            }
        },
        "TLSMaterial": {},
        "Storage": {
            "MetadataPath": "\u003cIN MEMORY\u003e",
            "TLSPath": "\u003cIN MEMORY\u003e"
        }
    }
]

@crazy-max
Copy link
Member Author

crazy-max commented Jul 21, 2025

  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.23.0-desktop.1
    Path:     /usr/local/lib/docker/cli-plugins/docker-buildx

@pechersky Seems you're not using a development version of buildx to test changes of this PR. You can build it on your side with https://github.com/docker/buildx?tab=readme-ov-file#building:

$ cd /tmp
$ docker buildx bake "https://github.com/docker/buildx.git#refs/pull/3320/merge"
$ mkdir -p ~/.docker/cli-plugins
$ mv ./bin/build/buildx ~/.docker/cli-plugins/docker-buildx

After testing don't forget to remove the binary:

$ rm ~/.docker/cli-plugins/docker-buildx

@pechersky
Copy link

Great! After deleting the previous builder, and rerunning, I get the expected output, I think.

$ docker buildx create --name wsltest --bootstrap --driver-opt "image=crazymax/buildkit:v0.23.2-ubuntu-nvidia" --buildkitd-flags "--debug"
[...]
$ docker inspect buildx_buildkit_wsltest0 | grep wsl
        "Name": "/buildx_buildkit_wsltest0",
                    "Source": "buildx_buildkit_wsltest0_state",
                    "Source": "/run/desktop/mnt/host/wsl/docker-desktop-bind-mounts/Ubuntu1/f969f076ad437ac0162d56bf356c2a910d8ddd313a6ac1d90246b6b64d06d59a",
                    "Target": "/usr/lib/wsl",
                "Name": "buildx_buildkit_wsltest0_state",
                "Source": "/var/lib/docker/volumes/buildx_buildkit_wsltest0_state/_data",
                "Source": "/run/desktop/mnt/host/wsl/docker-desktop-bind-mounts/Ubuntu1/f969f076ad437ac0162d56bf356c2a910d8ddd313a6ac1d90246b6b64d06d59a",
                "Destination": "/usr/lib/wsl",
                "desktop.docker.io/wsl-distro": "Ubuntu1",
$ docker buildx --builder wsltest build --progress=plain -f Dockerfile.test  .
[...]
#8 [2/2] RUN --device=nvidia/gpu=all nvidia-smi -L
#8 0.206 GPU 0: NVIDIA RTX A4500 Laptop GPU (UUID: GPU-ade25899-fff9-7c18-98dd-39132689d078)
#8 DONE 0.5s

@crazy-max
Copy link
Member Author

Great! After deleting the previous builder, and rerunning, I get the expected output, I think.

$ docker buildx create --name wsltest --bootstrap --driver-opt "image=crazymax/buildkit:v0.23.2-ubuntu-nvidia" --buildkitd-flags "--debug"
[...]
$ docker inspect buildx_buildkit_wsltest0 | grep wsl
        "Name": "/buildx_buildkit_wsltest0",
                    "Source": "buildx_buildkit_wsltest0_state",
                    "Source": "/run/desktop/mnt/host/wsl/docker-desktop-bind-mounts/Ubuntu1/f969f076ad437ac0162d56bf356c2a910d8ddd313a6ac1d90246b6b64d06d59a",
                    "Target": "/usr/lib/wsl",
                "Name": "buildx_buildkit_wsltest0_state",
                "Source": "/var/lib/docker/volumes/buildx_buildkit_wsltest0_state/_data",
                "Source": "/run/desktop/mnt/host/wsl/docker-desktop-bind-mounts/Ubuntu1/f969f076ad437ac0162d56bf356c2a910d8ddd313a6ac1d90246b6b64d06d59a",
                "Destination": "/usr/lib/wsl",
                "desktop.docker.io/wsl-distro": "Ubuntu1",
$ docker buildx --builder wsltest build --progress=plain -f Dockerfile.test  .
[...]
#8 [2/2] RUN --device=nvidia/gpu=all nvidia-smi -L
#8 0.206 GPU 0: NVIDIA RTX A4500 Laptop GPU (UUID: GPU-ade25899-fff9-7c18-98dd-39132689d078)
#8 DONE 0.5s

Yes looks good great!

@pechersky
Copy link

Strangely, if I rerun the buildx build command right after the successful build, it fails:

[...]
#7 DONE 12.3s

#8 [2/2] RUN --device=nvidia/gpu=all nvidia-smi -L
#8 0.210 GPU 0: NVIDIA RTX A4500 Laptop GPU (UUID: GPU-ade25899-fff9-7c18-98dd-39132689d078)
#8 DONE 0.5s
WARNING: No output specified with docker-container driver. Build result will only remain in the build cache. To push result image into registry use --push or to load image into docker use --load
$ docker buildx --builder wsltest build --progress=plain -f Dockerfile.test  .
#0 building with "wsltest" instance using docker-container driver

#1 [internal] load build definition from Dockerfile.test
#1 transferring dockerfile: 134B done
#1 DONE 0.0s

#2 resolve image config for docker-image://docker.io/docker/dockerfile:1.17-labs
#2 DONE 0.3s

#3 docker-image://docker.io/docker/dockerfile:1.17-labs@sha256:9187104f31e3a002a8a6a3209ea1f937fb7486c093cbbde1e14b0fa0d7e4f1b5
#3 resolve docker.io/docker/dockerfile:1.17-labs@sha256:9187104f31e3a002a8a6a3209ea1f937fb7486c093cbbde1e14b0fa0d7e4f1b5 0.0s done
#3 CACHED

#4 [internal] load metadata for docker.io/library/ubuntu:latest
#4 DONE 0.2s

#5 [internal] load .dockerignore
#5 transferring context: 114B done
#5 DONE 0.0s

#6 [1/2] FROM docker.io/library/ubuntu:latest@sha256:a08e551cb33850e4740772b38217fc1796a66da2506d312abe51acda354ff061
#6 resolve docker.io/library/ubuntu:latest@sha256:a08e551cb33850e4740772b38217fc1796a66da2506d312abe51acda354ff061 0.0s done
#6 CACHED

#7 [2/2] RUN --device=nvidia/gpu=all nvidia-smi -L
#7 0.044 /bin/sh: 1: nvidia-smi: not found
#7 ERROR: process "/bin/sh -c nvidia-smi -L" did not complete successfully: exit code: 127
------
 > [2/2] RUN --device=nvidia/gpu=all nvidia-smi -L:
0.044 /bin/sh: 1: nvidia-smi: not found
------
WARNING: No output specified with docker-container driver. Build result will only remain in the build cache. To push result image into registry use --push or to load image into docker use --load
Dockerfile.test:4
--------------------
   2 |     FROM ubuntu
   3 |     
   4 | >>> RUN --device=nvidia/gpu=all nvidia-smi -L
   5 |     
--------------------
ERROR: failed to build: failed to solve: process "/bin/sh -c nvidia-smi -L" did not complete successfully: exit code: 127

@crazy-max
Copy link
Member Author

Strangely, if I rerun the buildx build command right after the successful build, it fails:

Can you show the output of docker exec -it buildx_buildkit_wsltest0 cat /etc/cdi/nvidia.yaml please?

@pechersky
Copy link

$ docker exec -it buildx_buildkit_wsltest0 cat /etc/cdi/nvidia.yaml
---
cdiVersion: 0.3.0
containerEdits:
  env:
  - NVIDIA_VISIBLE_DEVICES=void
  hooks:
  - args:
    - nvidia-cdi-hook
    - create-symlinks
    - --link
    - /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68/nvidia-smi::/usr/bin/nvidia-smi
    env:
    - NVIDIA_CTK_DEBUG=false
    hookName: createContainer
    path: /usr/bin/nvidia-cdi-hook
  - args:
    - nvidia-cdi-hook
    - update-ldcache
    - --folder
    - /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68
    - --folder
    - /usr/lib/wsl/lib
    env:
    - NVIDIA_CTK_DEBUG=false
    hookName: createContainer
    path: /usr/bin/nvidia-cdi-hook
  mounts:
  - containerPath: /usr/lib/wsl/lib/libdxcore.so
    hostPath: /usr/lib/wsl/lib/libdxcore.so
    options:
    - ro
    - nosuid
    - nodev
    - bind
  - containerPath: /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68/libcuda.so.1.1
    hostPath: /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68/libcuda.so.1.1
    options:
    - ro
    - nosuid
    - nodev
    - bind
  - containerPath: /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68/libcuda_loader.so
    hostPath: /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68/libcuda_loader.so
    options:
    - ro
    - nosuid
    - nodev
    - bind
  - containerPath: /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68/libnvdxgdmal.so.1
    hostPath: /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68/libnvdxgdmal.so.1
    options:
    - ro
    - nosuid
    - nodev
    - bind
  - containerPath: /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68/libnvidia-ml.so.1
    hostPath: /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68/libnvidia-ml.so.1
    options:
    - ro
    - nosuid
    - nodev
    - bind
  - containerPath: /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68/libnvidia-ml_loader.so
    hostPath: /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68/libnvidia-ml_loader.so
    options:
    - ro
    - nosuid
    - nodev
    - bind
  - containerPath: /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68/libnvidia-ptxjitcompiler.so.1
    hostPath: /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68/libnvidia-ptxjitcompiler.so.1
    options:
    - ro
    - nosuid
    - nodev
    - bind
  - containerPath: /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68/nvcubins.bin
    hostPath: /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68/nvcubins.bin
    options:
    - ro
    - nosuid
    - nodev
    - bind
  - containerPath: /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68/nvidia-smi
    hostPath: /usr/lib/wsl/drivers/nvlt.inf_amd64_3b4f6ef9d0e51d68/nvidia-smi
    options:
    - ro
    - nosuid
    - nodev
    - bind
devices:
- containerEdits:
    deviceNodes:
    - path: /dev/dxg
  name: all
kind: nvidia.com/gpu

@pechersky
Copy link

Just to note -- if I delete the builder, then recreate it, then rerun the build, the first build always works.

@crazy-max
Copy link
Member Author

Strangely, if I rerun the buildx build command right after the successful build, it fails:

Hum I'm not able to repro.

First build:

$ docker buildx --builder wsltest build --progress=plain --no-cache .
...
#8 [1/2] FROM docker.io/library/ubuntu:latest@sha256:a08e551cb33850e4740772b38217fc1796a66da2506d312abe51acda354ff061
#8 resolve docker.io/library/ubuntu:latest@sha256:a08e551cb33850e4740772b38217fc1796a66da2506d312abe51acda354ff061 0.0s done
#8 sha256:32f112e3802cadcab3543160f4d2aa607b3cc1c62140d57b4f5441384f40e927 1.05MB / 29.72MB 0.2s
#8 sha256:32f112e3802cadcab3543160f4d2aa607b3cc1c62140d57b4f5441384f40e927 9.44MB / 29.72MB 0.3s
#8 sha256:32f112e3802cadcab3543160f4d2aa607b3cc1c62140d57b4f5441384f40e927 15.73MB / 29.72MB 0.5s
#8 sha256:32f112e3802cadcab3543160f4d2aa607b3cc1c62140d57b4f5441384f40e927 20.97MB / 29.72MB 0.6s
#8 sha256:32f112e3802cadcab3543160f4d2aa607b3cc1c62140d57b4f5441384f40e927 25.17MB / 29.72MB 0.8s
#8 sha256:32f112e3802cadcab3543160f4d2aa607b3cc1c62140d57b4f5441384f40e927 28.31MB / 29.72MB 0.9s
#8 sha256:32f112e3802cadcab3543160f4d2aa607b3cc1c62140d57b4f5441384f40e927 29.72MB / 29.72MB 1.1s done
#8 extracting sha256:32f112e3802cadcab3543160f4d2aa607b3cc1c62140d57b4f5441384f40e927
#8 extracting sha256:32f112e3802cadcab3543160f4d2aa607b3cc1c62140d57b4f5441384f40e927 0.7s done
#8 DONE 1.8s

#9 preparing device nvidia.com/gpu
#9 0.002 > /usr/bin/nvidia-smi -L
#9 0.044 GPU 0: NVIDIA GeForce RTX 3060 Ti (UUID: GPU-63109a83-ae03-3291-b519-c133b6caf78e)
#9 0.053 > apt-get update
#9 0.154 Get:1 http://security.ubuntu.com/ubuntu noble-security InRelease [126 kB]
#9 0.273 Get:2 http://security.ubuntu.com/ubuntu noble-security/multiverse amd64 Packages [23.0 kB]
#9 0.295 Get:3 http://security.ubuntu.com/ubuntu noble-security/restricted amd64 Packages [1848 kB]
#9 0.359 Get:4 http://archive.ubuntu.com/ubuntu noble InRelease [256 kB]
#9 0.376 Get:5 http://security.ubuntu.com/ubuntu noble-security/main amd64 Packages [1280 kB]
#9 0.407 Get:6 http://security.ubuntu.com/ubuntu noble-security/universe amd64 Packages [1131 kB]
#9 1.018 Get:7 http://archive.ubuntu.com/ubuntu noble-updates InRelease [126 kB]
#9 1.160 Get:8 http://archive.ubuntu.com/ubuntu noble-backports InRelease [126 kB]
#9 1.303 Get:9 http://archive.ubuntu.com/ubuntu noble/restricted amd64 Packages [117 kB]
#9 1.338 Get:10 http://archive.ubuntu.com/ubuntu noble/main amd64 Packages [1808 kB]
#9 1.681 Get:11 http://archive.ubuntu.com/ubuntu noble/universe amd64 Packages [19.3 MB]
#9 2.544 Get:12 http://archive.ubuntu.com/ubuntu noble/multiverse amd64 Packages [331 kB]
#9 2.547 Get:13 http://archive.ubuntu.com/ubuntu noble-updates/main amd64 Packages [1619 kB]
#9 2.574 Get:14 http://archive.ubuntu.com/ubuntu noble-updates/multiverse amd64 Packages [45.2 kB]
#9 2.574 Get:15 http://archive.ubuntu.com/ubuntu noble-updates/restricted amd64 Packages [1976 kB]
#9 2.609 Get:16 http://archive.ubuntu.com/ubuntu noble-updates/universe amd64 Packages [1443 kB]
#9 2.633 Get:17 http://archive.ubuntu.com/ubuntu noble-backports/main amd64 Packages [48.8 kB]
#9 2.634 Get:18 http://archive.ubuntu.com/ubuntu noble-backports/universe amd64 Packages [33.0 kB]
#9 3.172 Fetched 31.7 MB in 3s (10.3 MB/s)
#9 3.172 Reading package lists...
#9 3.859 > apt-get install -y gpg
#9 3.865 Reading package lists...
#9 4.452 Building dependency tree...
#9 4.612 Reading state information...
#9 4.758 The following additional packages will be installed:
#9 4.758   dirmngr gpg-agent gpgconf gpgv libksba8 libreadline8t64 libsqlite3-0
#9 4.759   pinentry-curses readline-common
#9 4.759 Suggested packages:
#9 4.759   gnupg dbus-user-session libpam-systemd pinentry-gnome3 tor keyboxd scdaemon
#9 4.759   pinentry-doc readline-doc
#9 4.790 The following NEW packages will be installed:
#9 4.791   dirmngr gpg gpg-agent gpgconf libksba8 libreadline8t64 libsqlite3-0
#9 4.792   pinentry-curses readline-common
#9 4.793 The following packages will be upgraded:
#9 4.793   gpgv
#9 4.992 1 upgraded, 9 newly installed, 0 to remove and 13 not upgraded.
#9 4.992 Need to get 2444 kB of archives.
#9 4.992 After this operation, 5597 kB of additional disk space will be used.
#9 4.992 Get:1 http://archive.ubuntu.com/ubuntu noble-updates/main amd64 gpgv amd64 2.4.4-2ubuntu17.3 [158 kB]
#9 5.453 Get:2 http://archive.ubuntu.com/ubuntu noble/main amd64 readline-common all 8.2-4build1 [56.5 kB]
#9 5.481 Get:3 http://archive.ubuntu.com/ubuntu noble/main amd64 libreadline8t64 amd64 8.2-4build1 [153 kB]
#9 5.589 Get:4 http://archive.ubuntu.com/ubuntu noble-updates/main amd64 libsqlite3-0 amd64 3.45.1-1ubuntu2.3 [701 kB]
#9 5.769 Get:5 http://archive.ubuntu.com/ubuntu noble-updates/main amd64 gpgconf amd64 2.4.4-2ubuntu17.3 [104 kB]
#9 5.782 Get:6 http://archive.ubuntu.com/ubuntu noble/main amd64 libksba8 amd64 1.6.6-1build1 [122 kB]
#9 5.819 Get:7 http://archive.ubuntu.com/ubuntu noble-updates/main amd64 dirmngr amd64 2.4.4-2ubuntu17.3 [323 kB]
#9 5.851 Get:8 http://archive.ubuntu.com/ubuntu noble-updates/main amd64 gpg amd64 2.4.4-2ubuntu17.3 [565 kB]
#9 5.889 Get:9 http://archive.ubuntu.com/ubuntu noble/main amd64 pinentry-curses amd64 1.2.1-3ubuntu5 [35.2 kB]
#9 5.891 Get:10 http://archive.ubuntu.com/ubuntu noble-updates/main amd64 gpg-agent amd64 2.4.4-2ubuntu17.3 [227 kB]
#9 6.059 debconf: delaying package configuration, since apt-utils is not installed
#9 6.091 Fetched 2444 kB in 1s (2186 kB/s)
(Reading database ... 8613 files and directories currently installed.)
#9 6.148 Preparing to unpack .../gpgv_2.4.4-2ubuntu17.3_amd64.deb ...
#9 6.164 Unpacking gpgv (2.4.4-2ubuntu17.3) over (2.4.4-2ubuntu17.2) ...
#9 6.229 Setting up gpgv (2.4.4-2ubuntu17.3) ...
#9 6.276 Selecting previously unselected package readline-common.
(Reading database ... 8613 files and directories currently installed.)
#9 6.281 Preparing to unpack .../0-readline-common_8.2-4build1_all.deb ...
#9 6.287 Unpacking readline-common (8.2-4build1) ...
#9 6.338 Selecting previously unselected package libreadline8t64:amd64.
#9 6.339 Preparing to unpack .../1-libreadline8t64_8.2-4build1_amd64.deb ...
#9 6.354 Adding 'diversion of /lib/x86_64-linux-gnu/libhistory.so.8 to /lib/x86_64-linux-gnu/libhistory.so.8.usr-is-merged by libreadline8t64'
#9 6.362 Adding 'diversion of /lib/x86_64-linux-gnu/libhistory.so.8.2 to /lib/x86_64-linux-gnu/libhistory.so.8.2.usr-is-merged by libreadline8t64'
#9 6.367 Adding 'diversion of /lib/x86_64-linux-gnu/libreadline.so.8 to /lib/x86_64-linux-gnu/libreadline.so.8.usr-is-merged by libreadline8t64'
#9 6.372 Adding 'diversion of /lib/x86_64-linux-gnu/libreadline.so.8.2 to /lib/x86_64-linux-gnu/libreadline.so.8.2.usr-is-merged by libreadline8t64'
#9 6.376 Unpacking libreadline8t64:amd64 (8.2-4build1) ...
#9 6.420 Selecting previously unselected package libsqlite3-0:amd64.
#9 6.421 Preparing to unpack .../2-libsqlite3-0_3.45.1-1ubuntu2.3_amd64.deb ...
#9 6.427 Unpacking libsqlite3-0:amd64 (3.45.1-1ubuntu2.3) ...
#9 6.468 Selecting previously unselected package gpgconf.
#9 6.470 Preparing to unpack .../3-gpgconf_2.4.4-2ubuntu17.3_amd64.deb ...
#9 6.475 Unpacking gpgconf (2.4.4-2ubuntu17.3) ...
#9 6.522 Selecting previously unselected package libksba8:amd64.
#9 6.523 Preparing to unpack .../4-libksba8_1.6.6-1build1_amd64.deb ...
#9 6.528 Unpacking libksba8:amd64 (1.6.6-1build1) ...
#9 6.577 Selecting previously unselected package dirmngr.
#9 6.578 Preparing to unpack .../5-dirmngr_2.4.4-2ubuntu17.3_amd64.deb ...
#9 6.594 Unpacking dirmngr (2.4.4-2ubuntu17.3) ...
#9 6.631 Selecting previously unselected package gpg.
#9 6.632 Preparing to unpack .../6-gpg_2.4.4-2ubuntu17.3_amd64.deb ...
#9 6.637 Unpacking gpg (2.4.4-2ubuntu17.3) ...
#9 6.683 Selecting previously unselected package pinentry-curses.
#9 6.684 Preparing to unpack .../7-pinentry-curses_1.2.1-3ubuntu5_amd64.deb ...
#9 6.689 Unpacking pinentry-curses (1.2.1-3ubuntu5) ...
#9 6.731 Selecting previously unselected package gpg-agent.
#9 6.732 Preparing to unpack .../8-gpg-agent_2.4.4-2ubuntu17.3_amd64.deb ...
#9 6.737 Unpacking gpg-agent (2.4.4-2ubuntu17.3) ...
#9 6.783 Setting up libksba8:amd64 (1.6.6-1build1) ...
#9 6.800 Setting up pinentry-curses (1.2.1-3ubuntu5) ...
#9 6.829 Setting up libsqlite3-0:amd64 (3.45.1-1ubuntu2.3) ...
#9 6.844 Setting up readline-common (8.2-4build1) ...
#9 6.866 Setting up libreadline8t64:amd64 (8.2-4build1) ...
#9 6.884 Setting up gpgconf (2.4.4-2ubuntu17.3) ...
#9 6.902 Setting up gpg (2.4.4-2ubuntu17.3) ...
#9 6.919 Setting up gpg-agent (2.4.4-2ubuntu17.3) ...
#9 7.281 Setting up dirmngr (2.4.4-2ubuntu17.3) ...
#9 7.386 Processing triggers for libc-bin (2.39-0ubuntu8.4) ...
#9 7.434 Downloading NVIDIA GPG key
#9 8.067 > apt-get update
#9 8.130 Hit:1 http://security.ubuntu.com/ubuntu noble-security InRelease
#9 8.133 Get:2 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64  InRelease [1581 B]
#9 8.300 Hit:3 http://archive.ubuntu.com/ubuntu noble InRelease
#9 8.405 Hit:4 http://archive.ubuntu.com/ubuntu noble-updates InRelease
#9 8.509 Hit:5 http://archive.ubuntu.com/ubuntu noble-backports InRelease
#9 9.347 Get:6 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64  Packages [737 kB]
#9 9.410 Fetched 739 kB in 1s (557 kB/s)
#9 9.410 Reading package lists...
#9 10.04 > apt-get install -y --no-install-recommends nvidia-container-toolkit-base
#9 10.04 Reading package lists...
#9 10.64 Building dependency tree...
#9 10.79 Reading state information...
#9 10.95 The following NEW packages will be installed:
#9 10.95   nvidia-container-toolkit-base
#9 11.53 0 upgraded, 1 newly installed, 0 to remove and 13 not upgraded.
#9 11.53 Need to get 3797 kB of archives.
#9 11.53 After this operation, 20.7 MB of additional disk space will be used.
#9 11.53 Get:1 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64  nvidia-container-toolkit-base 1.17.8-1 [3797 kB]
#9 11.69 debconf: delaying package configuration, since apt-utils is not installed
#9 11.72 Fetched 3797 kB in 1s (5794 kB/s)
#9 11.74 Selecting previously unselected package nvidia-container-toolkit-base.
(Reading database ... 8732 files and directories currently installed.)
#9 11.75 Preparing to unpack .../nvidia-container-toolkit-base_1.17.8-1_amd64.deb ...
#9 11.75 Unpacking nvidia-container-toolkit-base (1.17.8-1) ...
#9 11.99 Setting up nvidia-container-toolkit-base (1.17.8-1) ...
#9 12.04 time="2025-07-22T09:46:54Z" level=info msg="Using /usr/lib/x86_64-linux-gnu/libnvidia-ml.so.1"
#9 12.07 time="2025-07-22T09:46:54Z" level=info msg="Selecting /dev/dxg as /dev/dxtime="2025-07-22T09:46:54Z" level=info msg="Selecting /dev/dxg as /dev/dxg"
#9 12.07 time="2025-07-22T09:46:54Z" level=info msg="Using WSL driver store paths: [/usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f]"
#9 12.07 time="2025-07-22T09:46:54Z" level=info msg="Selecting /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libcuda.so.1.1 as /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libcuda.so.1.1"   
#9 12.07 time="2025-07-22T09:46:54Z" level=info msg="Selecting /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libcuda_loader.so as /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libcuda_loader.so"
#9 12.07 time="2025-07-22T09:46:54Z" level=info msg="Selecting /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libnvidia-ptxjitcompiler.so.1 as /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libnvidia-ptxjitcompiler.so.1"
#9 12.07 time="2025-07-22T09:46:54Z" level=info msg="Selecting /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libnvidia-ml.so.1 as /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libnvidia-ml.so.1"
#9 12.07 time="2025-07-22T09:46:54Z" level=info msg="Selecting /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libnvidia-ml_loader.so as /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libnvidia-ml_loader.so"
#9 12.07 time="2025-07-22T09:46:54Z" level=info msg="Selecting /usr/lib/wsl/lib/libdxcore.so as /usr/lib/wsl/lib/libdxcore.so"
#9 12.07 time="2025-07-22T09:46:54Z" level=info msg="Selecting /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libnvdxgdmal.so.1 as /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/libnvdxgdmal.so.1"
#9 12.07 time="2025-07-22T09:46:54Z" level=info msg="Selecting /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/nvcubins.bin as /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/nvcubins.bin"       
#9 12.07 time="2025-07-22T09:46:54Z" level=info msg="Selecting /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/nvidia-smi as /usr/lib/wsl/drivers/nvmdi.inf_amd64_f55cb1d07ac1033f/nvidia-smi"
#9 12.07 time="2025-07-22T09:46:54Z" level=info msg="Generated CDI spec with version 0.8.0"
#9 DONE 12.1s

#10 [2/2] RUN --device=nvidia.com/gpu nvidia-smi -L
#10 0.126 GPU 0: NVIDIA GeForce RTX 3060 Ti (UUID: GPU-63109a83-ae03-3291-b519-c133b6caf78e)
#10 DONE 0.7s

Second build:

$ docker buildx --builder wsltest build --progress=plain --no-cache .
#0 building with "wsltest" instance using docker-container driver

#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 128B done
#1 DONE 0.0s

#2 resolve image config for docker-image://docker.io/docker/dockerfile:1.17-labs
#2 DONE 0.4s

#3 docker-image://docker.io/docker/dockerfile:1.17-labs@sha256:9187104f31e3a002a8a6a3209ea1f937fb7486c093cbbde1e14b0fa0d7e4f1b5
#3 resolve docker.io/docker/dockerfile:1.17-labs@sha256:9187104f31e3a002a8a6a3209ea1f937fb7486c093cbbde1e14b0fa0d7e4f1b5 0.0s done
#3 CACHED

#4 [internal] load metadata for docker.io/library/ubuntu:latest
#4 DONE 0.2s

#5 [internal] load .dockerignore
#5 transferring context: 2B done
#5 DONE 0.0s

#6 [1/2] FROM docker.io/library/ubuntu:latest@sha256:a08e551cb33850e4740772b38217fc1796a66da2506d312abe51acda354ff061
#6 resolve docker.io/library/ubuntu:latest@sha256:a08e551cb33850e4740772b38217fc1796a66da2506d312abe51acda354ff061 0.0s done
#6 CACHED

#7 [2/2] RUN --device=nvidia.com/gpu nvidia-smi -L
#7 0.404 GPU 0: NVIDIA GeForce RTX 3060 Ti (UUID: GPU-63109a83-ae03-3291-b519-c133b6caf78e)
#7 DONE 0.4s

Third build:

docker buildx --builder wsltest build --progress=plain --no-cache .
#0 building with "wsltest" instance using docker-container driver

#1 [internal] load build definition from Dockerfile
#1 DONE 0.0s

#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 128B done
#1 DONE 0.0s

#2 resolve image config for docker-image://docker.io/docker/dockerfile:1.17-labs
#2 DONE 0.4s

#3 docker-image://docker.io/docker/dockerfile:1.17-labs@sha256:9187104f31e3a002a8a6a3209ea1f937fb7486c093cbbde1e14b0fa0d7e4f1b5
#3 resolve docker.io/docker/dockerfile:1.17-labs@sha256:9187104f31e3a002a8a6a3209ea1f937fb7486c093cbbde1e14b0fa0d7e4f1b5 0.0s done
#3 CACHED

#4 [internal] load metadata for docker.io/library/ubuntu:latest
#4 DONE 0.2s

#5 [internal] load .dockerignore
#5 transferring context: 2B done
#5 DONE 0.0s

#6 [1/2] FROM docker.io/library/ubuntu:latest@sha256:a08e551cb33850e4740772b38217fc1796a66da2506d312abe51acda354ff061
#6 resolve docker.io/library/ubuntu:latest@sha256:a08e551cb33850e4740772b38217fc1796a66da2506d312abe51acda354ff061 0.0s done
#6 CACHED

#7 [2/2] RUN --device=nvidia.com/gpu nvidia-smi -L
#7 0.111 GPU 0: NVIDIA GeForce RTX 3060 Ti (UUID: GPU-63109a83-ae03-3291-b519-c133b6caf78e)
#7 DONE 0.1s

I'm not sure what would make nvidia-smi not to be mounted anymore 🤔

@crazy-max
Copy link
Member Author

@tonistiigi Btw I think there is an issue with ondemand and autoallow behavior.

When I create a builder with nvidia build tag:

$ docker buildx create --name wsltest --bootstrap --driver-opt "image=crazymax/buildkit:v0.23.2-ubuntu-nvidia" --buildkitd-flags "--debug"

And inspect it before doing a build I have:

$ docker buildx inspect wsltest --bootstrap
...
Devices:
 Name:      nvidia.com/gpu
 On-Demand: true
...

After first build then I get:

$ docker buildx inspect wsltest --bootstrap
...
Devices:
 Name:                  nvidia.com/gpu=all
 Automatically allowed: true
...

If I restart the Docker Engine and inspecting this builder again I have:

$ docker buildx inspect wsltest --bootstrap
...
Devices:
 Name:                  nvidia.com/gpu=all
 Automatically allowed: false
...

I think as the generated CDI specification is loaded from the build, it takes precedence over the OnDemand and therefore the device is not automatically allowed anymore.

@pechersky
Copy link

pechersky commented Jul 30, 2025

Sorry for the noise. I understand now that the /etc/cdi/nvidia.yaml is only available after we run some type of nvidia-smi -L in a build context. And my GPU access was fixed by a wsl restart.

@crazy-max
Copy link
Member Author

Sorry for the noise. I understand now that the /etc/cdi/nvidia.yaml is only available after we run some type of nvidia-smi -L in a build context.

It's available within the builder container on device request right before the build.

And my GPU access was fixed by a wsl restart.

Great 👍

Copy link
Member

@tonistiigi tonistiigi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems requesting GPU on container builder creation introduced in #3063 is not enough as some libraries are missing on WSL.

If that is the case, isn't this a bug in Moby if --gpus does not work correctly?

@crazy-max
Copy link
Member Author

It seems requesting GPU on container builder creation introduced in #3063 is not enough as some libraries are missing on WSL.

If that is the case, isn't this a bug in Moby if --gpus does not work correctly?

It works but not for nested containers, I will make a repro with dind to make sure of it.

@tonistiigi
Copy link
Member

In that case, I think we need to detect the dind environment more precisely. I see you have WSL_DISTRO_NAME but that doesn't seem strict enough on its own.

@crazy-max
Copy link
Member Author

In that case, I think we need to detect the dind environment more precisely. I see you have WSL_DISTRO_NAME but that doesn't seem strict enough on its own.

It's not really detecting the dind environment. When we create the container builder and request gpus:

if len(d.gpus) > 0 && d.hasGPUCapability(ctx, cfg.Image, d.gpus) {
hc.DeviceRequests = d.gpus
}

Moby will run the nvidia container runtime prestart hook that checks whether NVIDIA devices are requested and ensures GPU access is configured using the nvidia-container-cli from libnvidia-container.

In such case, necessary libraries are mounted and GPU is detected with nvidia-smi but when we generate the CDI spec within this container builder it doesn't have everything it needs for WSL. I think this is related to how nvidia container runtime prestart hook works. If instead of using --gpus we could use CDI when creating the container builder, I think it would work. But user would need to generate the CDI specs first on their host.

cc @elezar

@elezar
Copy link

elezar commented Aug 12, 2025

As a naive question: Some of the output above referred to RUN --device=nvidia/gpu=all nvidia-smi -L. How does this differ from RUN --device=nvidia.com/gpu=all nvidia-smi -L which refers the "correct" CDI device name? Is buildkit performing some mapping behind the scenes?

@crazy-max in the WSL case, where is the "outer" CDI spec being created (or should it be created)? Is this in the WSL2 distribution? Could a spec be generated For Docker Desktop as the VM is being started?

On a related note, I have created moby/moby#50228 as a placeholder for migrating the --gpus flag to CDI and we could consider this as one of the use cases to enable there.

@crazy-max
Copy link
Member Author

@elezar

As a naive question: Some of the output above referred to RUN --device=nvidia/gpu=all nvidia-smi -L. How does this differ from RUN --device=nvidia.com/gpu=all nvidia-smi -L which refers the "correct" CDI device name? Is buildkit performing some mapping behind the scenes?

Yes we have the device name format defined here: https://docs.docker.com/reference/dockerfile/#run---device:

  • vendor1.com/device: request the first device found for this vendor
  • vendor1.com/device=foo: request a specific device
  • vendor1.com/device=*: request all devices for this vendor

in the WSL case, where is the "outer" CDI spec being created (or should it be created)? Is this in the WSL2 distribution?

We don't handle CDI specs from the host for the container builder case atm. We use the nvidia-container-runtime-hook that seems to miss some mounts for nested containers when working in WSL. It works fine on Linux though.

Could a spec be generated For Docker Desktop as the VM is being started?

Yes good point, that might be something Docker Desktop could do.

On a related note, I have created moby/moby#50228 as a placeholder for migrating the --gpus flag to CDI and we could consider this as one of the use cases to enable there.

Ah that looks ideal, I see the nvidia-cdi-hook, I think this would work.

@tonistiigi tonistiigi merged commit 10605b8 into docker:master Aug 13, 2025
201 of 202 checks passed
@crazy-max crazy-max deleted the mount-wsl-lib branch August 13, 2025 18:40
aevesdocker pushed a commit to docker/docs that referenced this pull request Aug 26, 2025
follow-up
#23069 (comment)

## Related issues or tickets

* docker/buildx#3320

## Reviews

<!-- Notes for reviewers here -->
<!-- List applicable reviews (optionally @tag reviewers) -->

- [ ] Technical review
- [ ] Editorial review
- [ ] Product review

Signed-off-by: CrazyMax <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants