nvidia-docker registers a new container runtime to the Docker daemon.
You must select the nvidia runtime when using docker run:
docker run --runtime=nvidia --rm nvidia/cuda nvidia-smi
Set the environment variable NVIDIA_VISIBLE_DEVICES in the container:
docker run --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=0 --rm nvidia/cuda nvidia-smi
Setting NVIDIA_VISIBLE_DEVICES will enable GPU support for any container image:
docker run --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=all --rm debian:stretch nvidia-smi
If the environment variables are set inside the Dockerfile, you don't need to set them on the docker run command-line.
For instance, if you are creating your own custom CUDA container, you should use the following:
ENV NVIDIA_VISIBLE_DEVICES all
ENV NVIDIA_DRIVER_CAPABILITIES compute,utilityThese environment variables are already set in our official images pushed to Docker Hub.
For a Dockerfile using the NVIDIA Video Codec SDK, you should use:
ENV NVIDIA_VISIBLE_DEVICES all
ENV NVIDIA_DRIVER_CAPABILITIES compute,video,utility