Home > Software design >  How to select specific GPUs in docker-compose
How to select specific GPUs in docker-compose

Time:02-04

On a machine with multiple Nvidia GPUs, is there a way to specify in the docker-compose.yml file that we want to use two specific GPU device IDs in the Docker container?

The following seems to be the equivalent of docker run --gpus=allsince all the GPUs are listed when runningnvidia-smi` inside the Docker container.

    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              capabilities: [gpu]

CodePudding user response:

You may use device_ids or count.

For example, to allow only GPUs with ID 0 and 3:

deploy:
    resources:
        reservations:
            devices:
                - driver: nvidia
                  device_ids: ['0', '3']
                  capabilities: [gpu]

Enabling GPU access with Compose

  • Related