How to make "--gpus all" the default

I’m using docker on an nvidia enabled host. Started with Docker 19.x the installation and usage are slightly different. There’s no nvidia runtime anymore which I could put it to daemon.json, but we can achieve the same by passing eg. “–gpus all” to docker run.

However, I have a pretty rigid environment where I can’t simply pass it to docker run, so I need to make this behaviour as the default somehow. But I can’t find how in the docs.

So my question is how to make it work, how to use the gpus without specifying it for docker run?

Janos

1 Like

Hey did you end up finding a solution for this? I’m having the same issue

+1
I am having the same problem.
I need to run docker containers from gitlab-runner with executor docker. Are there any options for how to do this by default from docker engine ?

I haven’t found a direct way to do this, but maybe this is a valid workaround.

If you set the default runtime to nvidia in the /etc/docker/daemon.json then you can use an env variable to make GPUs visible to the runtime this way:

docker run -it --rm -e NVIDIA_VISIBLE_DEVICES=all ubuntu nvidia-smi

As you can see, you don’t need to add --gpus all at all but the env var is required.

Regards.