1

my docker compose file is as follows:

version: "3"

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "5000:5000"
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: 1
              capabilities: [gpu]

I am trying to allow my container to have GPU access. The same thing can happen with docker run --gpus all but I want it with docker compose. The yml above produces this error:

ERROR: The Compose file './docker-compose.yml' is invalid because:
services.app.deploy.resources.reservations value Additional properties are not allowed ('devices' was unexpected)

I don't understand how can this be a problem since what I used is what the official docs have (link).

Any ideas?

1 Answer 1

2

The deploy section is intended for Swarm deployments, and the resources key under deploy is used to configure resource reservations like CPU and memory. For GPU access, you should use a different method.

To enable GPU access in your Docker Compose file, you can use the runtime key under the service, like this:

version: "3"

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "5000:5000"
    runtime: nvidia  # This enables GPU access for the service
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.