To automate the configuration (docker run
arguments) used to launch a docker container, I am writing a docker-compose.yml
file.
My container should have access to the GPU, and so I currently use docker run --gpus=all
parameter. This is described in the Expose GPUs for use docs:
Include the
--gpus
flag when you start a container to access GPU resources. Specify how many GPUs to use. For example:$ docker run -it --rm --gpus all ubuntu nvidia-smi
Unfortunately, Enabling GPU access with Compose doesn't describe this use case exactly. This guide uses the deploy
yaml element, but in the context of reserving machines with GPUs. In fact, another documentation says that it will be ignored by docker-compose
:
This only takes effect when deploying to a swarm with docker stack deploy, and is ignored by docker-compose up and docker-compose run.
After trying it and solving a myriad of problems along the way, I have realized that it is simply the documentation that is out of date.
Adding the following yaml block to my docker-compose.yml
resulted in nvidia-smi
being available to use.
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1 # alternatively, use `count: all` for all GPUs
capabilities: [gpu]