Docker flag "--gpu" does not work without sudo command

Viewed 892

I'm ubuntu user. I use the following docker image, tensorflow/tensorflow:nightly-gpu

If I try to run this command

$ docker run -it --rm --gpus all tensorflow/tensorflow:nightly-gpu bash

There's permission denied error.

docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: Running hook #0:: error running hook: exit status 1, stdout: , stderr: nvidia-container-cli: mount error: open failed: /sys/fs/cgroup/devices/user.slice/devices.allow: permission denied: unknown.

Of course, I can run this command if I am using sudo, but I want to use gpu without sudo.

Is there any good solution? Any leads, please?

1 Answers

As your problem seems to be only when running "--gpu".

Add/update these two sections of /etc/nvidia-container-runtime/config.toml

[nvidia-container-cli]
no-cgroups = true

[nvidia-container-runtime]
debug = "/tmp/nvidia-container-runtime.log"

Source: https://github.com/containers/podman/issues/3659#issuecomment-543912380

If you can't use docker without sudo at all

If you are running in a Linux environment, you need to create a user for docker so you won't need to use sudo every time. Below are the steps to create:

$ sudo groupadd docker

$ sudo usermod -aG docker $USER

$ newgrp docker 

Source: https://docs.docker.com/engine/install/linux-postinstall/

Related