1. 安装方式

1. 在线安装

  1. # 默认安装位置:/usr/bin/
  2. sudo apt-get install nvidia-container-runtime

2. 离线安装

  1. 获取离线安装包。

配置域名解析

vi /etc/hosts

添加以下条目

185.199.109.153 nvidia.github.io

  1. - **安装apt-transport-https**
  2. ```bash
  3. wget http://ftp.hk.debian.org/debian/pool/main/a/apt/apt-transport-https_1.0.9.8.4_amd64.deb
  4. dpkg -i apt-transport-https_*_amd64.deb
  • 软件源配置

    1. distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
    2. curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
    3. curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
    4. sudo apt-get update
  • 联网下载安装包

    1. apt-get download libnvidia-container1
    2. apt-get download libnvidia-container-tools
    3. apt-get download nvidia-container-runtime-hook
    4. apt-get download nvidia-container-runtime
    5. apt-get download nvidia-docker2
  1. 离线安装。
    1. # 注意:顺序不能颠倒
    2. dpkg -i libnvidia-container1_1.0.5-1_amd64.deb
    3. dpkg -i libnvidia-container-tools_1.0.5-1_amd64.deb
    4. dpkg -i nvidia-container-runtime-hook_1.4.0-1_amd64.deb
    5. dpkg -i nvidia-container-runtime_2.0.0+docker18.06.2-1_amd64.deb
    6. dpkg -i nvidia-docker2_2.0.3+docker18.06.2-1_all.deb

    2. 配置

    1. # 配置默认nvidia运行(安装成功或一般会默认安装上)
    2. sudo vi /etc/docker/daemon.json
    内容如下:
    1. {
    2. "default-runtime": "nvidia"
    3. "runtimes": {
    4. "nvidia": {
    5. "path": "/usr/bin/nvidia-container-runtime",
    6. "runtimeArgs": []
    7. }
    8. }
    9. }
    重启Docker:
    1. # 重启docker服务即可生效
    2. sudo systemctl daemon-reload
    3. sudo systemctl restart docker

    3. 验证

    1. sudo docker run --runtime=nvidia --rm hello-world
    2. sudo docker run --runtime=nvidia --rm nvidia/cuda:9.0-base nvidia-smi

    4. 移除

    1. sudo apt-get purge libnvidia-container1
    2. sudo apt-get purge libnvidia-container-tools
    3. sudo apt-get purge nvidia-container-runtime-hook
    4. sudo apt-get purge nvidia-container-runtime
    5. sudo apt-get purge nvidia-docker2

    参考

    博文:docker 和 nvidia-docker 的离线安装和基本使用
    https://fanfuhan.github.io/2019/11/22/docker_based_use/