Support for NVIDIA GPUs under Docker Compose
Problem
Under Docker 19.03.0 Beta 2, support for NVIDIA GPU has been introduced in the form of new CLI API --gpus. https://github.com/docker/cli/pull/1714 talk about this enablement. Now one can simply pass --gpus option for GPU-accelerated Docker based application. [code block] As of today, Compose doesn't support this. This is a feature request for enabling Compose to support for NVIDIA GPU.
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Enable NVIDIA GPU Support in Docker Compose
Docker Compose currently does not support the --gpus option introduced in Docker 19.03.0 Beta 2. This limitation prevents users from utilizing NVIDIA GPUs for GPU-accelerated applications within Docker Compose configurations.
Awaiting Verification
Be the first to verify this fix
- 1
Update Docker Compose Version
Ensure you are using the latest version of Docker Compose that may include support for the --gpus option. Check the official Docker Compose repository for any updates or release notes.
bashdocker-compose --version - 2
Modify docker-compose.yml
Add the 'deploy.resources.limits.gpus' section to your docker-compose.yml file to specify the number of GPUs required by your service.
yamlversion: '3.8' services: my_service: image: my_image deploy: resources: limits: gpus: '1' - 3
Test GPU Access
Run your Docker Compose application and verify that it can access the NVIDIA GPU. Use nvidia-smi within the container to check GPU availability.
bashdocker-compose up -d docker-compose exec my_service nvidia-smi - 4
Check for Errors
Monitor the logs of your Docker Compose application for any errors related to GPU access. Use 'docker-compose logs' to view the logs.
bashdocker-compose logs
Validation
Confirm that the application runs without errors and that the output of 'nvidia-smi' shows the expected GPU information. Additionally, ensure that the application utilizes the GPU as intended.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep