Nvidia docker container runtime doesn't detect my gpu

Hello @Traktorbek!

You need to adapt your docker-compose file so that it uses the CDI driver, like documented in Nixpkgs Reference Manual. In your case, it should be along the lines:

pipeline:
  image: '${DOCKER_IMAGE_PIPELINE?Variable not set}:${TAG-latest}'
  build:
    target: development
    context: ./pipeline
    args:
      - PIPELINE_BASE_IMAGE=${PIPELINE_BASE_IMAGE}
  environment:
    - CONFIG_PATH=${PIPELINE_CONFIG_PATH}
  runtime: ${DOCKER_RUNTIME:-runc}
  restart: always
  deploy:
    resources:
      reservations:
        devices:
        - driver: cdi
          device_ids:
          - nvidia.com/gpu=all

Note that this will expose all your GPU’s to the container, if they are being identified by their ID, and you wanted to expose only ID’s 0 and 1, you could do:

pipeline:
  image: '${DOCKER_IMAGE_PIPELINE?Variable not set}:${TAG-latest}'
  build:
    target: development
    context: ./pipeline
    args:
      - PIPELINE_BASE_IMAGE=${PIPELINE_BASE_IMAGE}
  environment:
    - CONFIG_PATH=${PIPELINE_CONFIG_PATH}
  runtime: ${DOCKER_RUNTIME:-runc}
  restart: always
  deploy:
    resources:
      reservations:
        devices:
        - driver: cdi
          device_ids:
          - nvidia.com/gpu=0
          - nvidia.com/gpu=1
3 Likes