Utilizing Host Machine GPU in Docker Compose for ML Applications: Troubleshooting the 'devices' Error

Hey everyone, I’m seeking assistance with leveraging the host machine GPU via Docker Compose for my machine learning (ML) application. I encountered an error when attempting to run docker-compose up, and I’d appreciate any guidance on resolving it.

Error Message:

$ docker-compose up

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

docker-compose.yml:

version: "3.3"

services:
  event_analysis:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - 5000:5000
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]
    command: nvidia-smi

Docker and Docker-Compose versions being used:

$ docker --version
Docker version 24.0.5, build 24.0.5-0ubuntu1~20.04.1

$ docker-compose --version
docker-compose version 1.25.0, build unknown

I’m specifically looking to achieve this using Docker Compose and not Docker Swarm. Any insights or solutions would be greatly appreciated. Thanks in advance for your help!. :rocket: docker #GPU
#MachineLearning