In Docker Compose file, how to enable GPU in service build instructions?

Viewed 70

I am trying to build service from docker file when start docker compose. The docker-compose.yml looks like:

version: '3'

services:
  app:
    build:
      context: .
    shm_size: 4gb
# ...

The build process need to enable GPU. I know how to enable GPU in deploy according to this blog. But it seems docker compose file build do not support GPU.

1 Answers

I think, I have read two different method. The simple, try that: https://docs.docker.com/compose/gpu-support/ https://www.tremplin-numerique.org/en/how-to-run-compose-docker-containers-with-gpu-access

  services:
  test:
    image: nvidia/cuda:10.2-base
    command: nvidia-smi
    runtime: nvidia

The complex, It run a docker via a run. Then via docker compose, it connect to its docker.

In this method, it describes all steps. https://dinhanhthi.com/docker-gpu/

docker run \
    --gpus all\
    --name docker_thi_test\
    --rm\
    -v abc:abc\
    -p 8888:8888

Yaml

version: '2'
services:
  jupyter:
    container_name: 'docker_thi_test'
    build: .
    volumes:
        - ./notebooks:/tf/notebooks 

    ports:
        - 8888:8888 

    environment:
        - NVIDIA_VISIBLE_DEVICES=0 

        - PASSWORD=12345
Related