Nvidia-docker: Unknown flag --gpus error from subprocess module

Created on 21 Feb 2020  路  3Comments  路  Source: NVIDIA/nvidia-docker

I'm executing a docker command using Python's subprocess module. Although the --gpus flag from the terminal works correctly as expected, it seems that there is an issue when running the same command from a python script using the subprocess.run command.

the error message is:

  uknown flag: --gpus all
  see 'docker run --help'

Basic test:

 import subprocess

 my_cmd =  ["docker", "run", "--gpus all", "nvidia:cuda:9.0-base","nvidia-smi"]
 subprocess.run(launch_defense_cmd)

As mentioned above, the same command works perfectly fine from the terminal.

docker run --gpus all nvidia/cuda:10.0-base nvidia-smi

```
Fri Feb 21 19:56:42 2020
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 440.33.01 Driver Version: 440.33.01 CUDA Version: 10.2 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce RTX 208... On | 00000000:01:00.0 On | N/A |
| 32% 33C P8 20W / 250W | 1228MiB / 11016MiB | 4% Default |
+-------------------------------+----------------------+----------------------+
| 1 GeForce RTX 208... On | 00000000:02:00.0 Off | N/A |
| 30% 29C P8 15W / 250W | 1MiB / 11019MiB | 0% Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
+-----------------------------------------------------------------------------+

some helpful information:

kernel version: 
   `5.3.0-40-generic #32~18.04.1-Ubuntu SMP Mon Feb 3 14:05:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux`

docker version:

  Client: Docker Engine - Community

Version: 19.03.5
API version: 1.40
Go version: go1.12.12
Git commit: 633a0ea838
Built: Wed Nov 13 07:29:52 2019
OS/Arch: linux/amd64
Experimental: false

Server: Docker Engine - Community
Engine:
Version: 19.03.5
API version: 1.40 (minimum version 1.12)
Go version: go1.12.12
Git commit: 633a0ea838
Built: Wed Nov 13 07:28:22 2019
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.2.10
GitCommit: b34a5c8af56e510852c35414db4c1f4fa6172339
runc:
Version: 1.0.0-rc8+dev
GitCommit: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
docker-init:
Version: 0.18.0
GitCommit: fec3683

nvidia container library version

version: 1.0.5
build date: 2019-09-06T16:59+00:00
build revision: 13b836390888f7b7c7dca115d16d7e28ab15a836
build compiler: x86_64-linux-gnu-gcc-7 7.4.0
build platform: x86_64
```

Most helpful comment

my_cmd =  ["docker", "run", "--gpus", "all", "nvidia/cuda:9.0-base","nvidia-smi"]
subprocess.run([" ".join(my_cmd)], shell=True)

All 3 comments

Pretty sure this should be: ["docker", "run", "--gpus", "all", "nvidia:cuda:9.0-base","nvidia-smi"]

Hope this helps!

@RenaudWasTaken I wish that was the case. I just tested it and its still not working

my_cmd =  ["docker", "run", "--gpus", "all", "nvidia/cuda:9.0-base","nvidia-smi"]
subprocess.run([" ".join(my_cmd)], shell=True)
Was this page helpful?
0 / 5 - 0 ratings