doom4
doom4

Reputation: 695

Docker Engine API enable GPU in create call

I would like to avoid installing the docker cli to create a docker sibling and hence create/start/remove a docker container using the docker engine api. For non GPU tasks this works great but not for containers which need the GPU. For example to create:

curl -s -X POST --unix-socket /var/run/docker.sock -H "Content-Type: application/json" -d '{"Image": "nvidia/cuda:11.8.0-base-ubuntu22.04", "Cmd": ["nvidia-smi"], "AttachStdout": true}' http://localhost/containers/create

works but starting it doesn't work since the GPU is missing. I can't find in the reference (https://docs.docker.com/engine/api/v1.43/) how to attach the gpu of the system.

I can create this via the cli and then start it without issues on the machine:

docker create --gpus all nvidia/cuda:11.8.0-base-ubuntu22.04 nvidia-smi

According to the docker create reference (https://docs.docker.com/engine/reference/commandline/create/) the --gpus is available since API 1.40+. Any idea how to do this in the curl command?

Upvotes: 0

Views: 276

Answers (1)

doom4
doom4

Reputation: 695

For those who have the same question you need to specify in the create call the DeviceRequests option using the list:

"DeviceRequests": [
  {
    "Driver": "nvidia",
    "DeviceIDs"": [
      "0"
    ],
    "Capabilities": [
       [
         "gpu",
       ]
   }
]

I finally found this in the depth of the reference but only in the Request samples not in the actual API description. More details also here: https://docs.docker.com/compose/gpu-support/

Upvotes: 0

Related Questions