I'm using docker compose to run a container:
version: "3.9"
services:
app:
image: nvidia/cuda:11.0.3-base-ubuntu20.04
deploy:
resources:
reservations:
devices:
- capabilities: [ gpu ]
The container can benefit from the presence of a GPU, but it does not strictly need one. Using the above docker-compose.yaml results in an error
Error response from daemon: could not select device driver "" with capabilities: [[gpu]]
when being used on a machine without a GPU. Is it possible to specify "use a GPU, if one is available, else start the container without one"?
While not being fully automatic, there at least exists an option to disable the GPU, using a profile, so that users can switch off GPU usage without fiddling with the docker-compose.yaml, but instead using a CLI flag.
Here is an example for how to remove the deploy section, based on the presence of a CLI parameter. The relevant part is:
services:
...
auto-cpu:
<<: *automatic
profiles: ["auto-cpu"]
deploy: {}
I hope this helps.
@herku, there are no conditional statements in docker compose. In 2018 the feature was out of scope https://github.com/docker/compose/issues/5756
Anyway you can check this answer with options how to workaround the problem https://stackoverflow.com/a/50393225/3730077
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With