Problem with using GPU with Docker-compose

  docker, docker-compose, nvidia-docker

I want to run a container based on python:3.8.8-slim-buster that needs access to the GPU.

When I build it from this Dockerfile:

FROM python:3.8.8-slim-buster

CMD ["sleep", "infinity"]

and then run it with "–gpus all" flag and exec nvidia-smi i get a proper response:

Sat Jun 19 12:26:57 2021       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 465.27       Driver Version: 465.27       CUDA Version: 11.3     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ...  Off  | 00000000:01:00.0 Off |                  N/A |
| N/A   45C    P8    N/A /  N/A |    301MiB /  1878MiB |     14%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
+-----------------------------------------------------------------------------+

and when I use this docker-compose:

services:
    test:
      image: tensorflow/tensorflow:2.5.0-gpu
      command: sleep infinity
      deploy:
        resources:
          reservations:
            devices:
            - capabilities: [gpu]

and exec nvidia-smi after running it i get the same response.
But when i replace the image in the docker-compose to python:3.8.8-slim-buster like in the Dockerfile, i get this response:

OCI runtime exec failed: exec failed: container_linux.go:380: starting container process caused: exec: "nvidia-smi": executable file not found in $PATH: unknown

I appreciate any help figuring this out.

Source: Docker Questions

LEAVE A COMMENT