I need to run a docker image on two machines: one with GPU and the other without GPU. In order to use GPU, I currently pass the --gpus all option to docker run as follows (otherwise, GPU is not detected by pytorch code inside the container):
docker run -dt -P --name "ch4-dev" --label "..." -v ".../debugpy:/debugpy:ro,z" --entrypoint "python3" --gpus all "ch4:latest"
The above docker run command is assembled by VS Code python extension. It runs correctly on the machine with the GPU, and torch.cuda.is_available() returns True.
However, on the machine without GPU, the same project generates the following error:
docker: Error response from daemon: could not select device driver "" with capabilities: [[gpu]]. The terminal process failed to launch (exit code: 125).
The Question:
Is there a more flexible option than --gpu=all that will detect/use a GPU if exists, and otherwise fall back to using CPU gracefully without an error?