docker build with nvidia runtime docker build with nvidia runtime docker docker

docker build with nvidia runtime


You need use nvidia-container-runtime as explained in docs: "It is also the only way to have GPU access during docker build".

Steps for Ubuntu:

  1. Install nvidia-container-runtime:

    sudo apt-get install nvidia-container-runtime

  2. Edit/create the /etc/docker/daemon.json with content:

{    "runtimes": {        "nvidia": {            "path": "/usr/bin/nvidia-container-runtime",            "runtimeArgs": []         }     },    "default-runtime": "nvidia" }
  1. Restart docker daemon:

    sudo systemctl restart docker

  2. Build your image (now GPU available during build):

    docker build -t my_image_name:latest .


A "solution" I found is to first run a base image with the host nvidia drivers mounted on it

docker run -it --rm --gpus ubuntu

And then build my app within the container manually and commit the resulting image.This is not ideal and it would be best to have access to nvidia-smi during the build phase.


You have to install the NVIDIA driver and Docker 19.03 for your Linux distribution Note that you do not need to install the CUDA toolkit on the host, but the driver needs to be installed

With the release of Docker 19.03, usage of nvidia-docker2 packages are deprecated since NVIDIA GPUs are now natively supported as devices in the Docker runtime.

If you are using the nvidia-docker2 packages, review the instructions in the “Upgrading with nvidia-docker2”.

For first-time users of Docker 19.03 and GPUs, continue with the instructions for getting started below. Usage

# Add the package repositoriesdistribution=$(. /etc/os-release;echo $ID$VERSION_ID)curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.listsudo apt-get update && sudo apt-get install -y nvidia-container-toolkitsudo systemctl restart docker

for more information please visit : https://github.com/NVIDIA/nvidia-docker