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?
For those who have the same question you need to specify in the create call the DeviceRequests option using the list:
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/