使用nvidia运行时构建docker [英] docker build with nvidia runtime

查看:77
本文介绍了使用nvidia运行时构建docker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个GPU应用程序,它在图像构建阶段进行单元测试.使用Docker 19.03,可以使用 docker run --gpus all 指定nvidia运行时,但是我还需要访问 docker build 的gpus,因为我需要进行单元测试.我怎样才能实现这个目标?

I have a GPU application that does unit-testing during the image building stage. With Docker 19.03, one can specify nvidia runtime with docker run --gpus all but I also need access to the gpus for docker build because I do unit-testing. How can I achieve this goal?

对于使用nvidia-docker2的旧版docker,无法在构建阶段指定运行时,但是您可以将默认运行时设置为nvidia,并且docker build可以正常工作.我可以在不再需要nvidia-docker的Docker 19.03中做到这一点吗?如果可以,怎么办?

For older version of docker that use nvidia-docker2 it was not possible to specifiy runtime during build stage, BUT you can set the default runtime to be nvidia, and docker build works fine that way. Can I do that in Docker 19.03 that doesn't need nvidia-docker anymore? If so, how?

推荐答案

您需要使用中所述docs :这也是在docker构建期间访问GPU的唯一方法."

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

Ubuntu的步骤:

Steps for Ubuntu:

  1. 安装nvidia-container-runtime:

  1. Install nvidia-container-runtime:

sudo apt-get install nvidia-container-runtime

使用内容编辑/创建/etc/docker/daemon.json:

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

{
    "runtimes": {
        "nvidia": {
            "path": "/usr/bin/nvidia-container-runtime",
            "runtimeArgs": []
         } 
    },
    "default-runtime": "nvidia" 
}

  1. 重新启动docker守护程序:

  1. Restart docker daemon:

sudo systemctl restart docker

构建图像(现在在构建过程中可以使用GPU):

Build your image (now GPU available during build):

docker build -t my_image_name:latest.

这篇关于使用nvidia运行时构建docker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆