Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I specify nvidia runtime from docker-compose.yml?

I am able to run a tensorflow container w/ access to the GPU from the command line w/ the following command

$ sudo docker run --runtime=nvidia --rm gcr.io/tensorflow/tensorflow:latest-gpu

I would like to be able to run this container from docker-compose. Is it possible to specify the --runtime flag from docker-compose.yml?

like image 651
rissem Avatar asked Nov 24 '17 02:11

rissem


People also ask

How do I use nvidia with Docker?

Using the NVIDIA Container Runtime for Docker Use docker run and specify runtime=nvidia . Use nvidia-docker run . The new package provides backward compatibility, so you can still run GPU-accelerated containers by using this command, and the new runtime will be used. Use docker run with nvidia as the default runtime.

What is nvidia container runtime?

NVIDIA Container Runtime is a GPU aware container runtime, compatible with the Open Containers Initiative (OCI) specification used by Docker, CRI-O, and other popular container technologies. It simplifies the process of building and deploying containerized GPU-accelerated applications to desktop, cloud or data centers.

How do I change my default Docker runtime?

Simply edit ~/. config/docker/daemon. json , and add crun to the list of runtimes, then set crun to be the default runtime.

Can I use GPU in Docker?

To use your GPU with Docker, begin by adding the NVIDIA Container Toolkit to your host. This integrates into Docker Engine to automatically configure your containers for GPU support. The Container Toolkit should now be operational. You're ready to start a test container.


1 Answers

Currently (Aug 2018), NVIDIA container runtime for Docker (nvidia-docker2) supports Docker Compose.

Yes, use Compose format 2.3 and add runtime: nvidia to your GPU service. Docker Compose must be version 1.19.0 or higher.

Example docker-compose.yml:

version: '2.3'  services:   nvsmi:     image: ubuntu:16.04     runtime: nvidia     environment:       - NVIDIA_VISIBLE_DEVICES=all     command: nvidia-smi 

More example from NVIDIA blog uses Docker Compose to show how to launch multiple GPU containers with the NVIDIA Container Runtime.

like image 122
cedrickchee Avatar answered Sep 25 '22 19:09

cedrickchee