How do I specify nvidia runtime from docker-compose.yml?
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.
You should edit /etc/docker/daemon.json
, adding the first level key "default-runtime": "nvidia"
, restart docker daemon (ex. "sudo service docker restart"
) and then all containers on that host will run with nvidia runtime.
More info on daemon.json
here
Or better: using systemd
and assuming the path is /usr/libexec/oci/hooks.d/nvidia
Configure
mkdir -p /etc/systemd/system/docker.service.d/cat > /etc/systemd/system/docker.service.d/nvidia-containers.conf <<EOF[Service]ExecStart=ExecStart=/usr/bin/dockerd -D --add-runtime nvidia=/usr/libexec/oci/hooks.d/nvidia --default-runtime=nvidiaEOF
Restart
systemctl daemon-reloadsystemctl restart docker
Demo
Don't need to specify --runtime=nvidia
since we set default-runtime=nvidia
in the configuration step.
docker run --rm gcr.io/tensorflow/tensorflow:latest-gpu
Solution Inspired from my tutorial about KATA runtime.