阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Ubuntu 18.04安装Docker CE及nvidia-docker2流程

123次阅读
没有评论

共计 2415 个字符,预计需要花费 7 分钟才能阅读完成。

Docker 的好处之一,就是在 Container 里面可以随意瞎搞,不用担心弄崩 Host 的环境。
nvidia-docker2 的好处是 NVidia 帮你配好了 Host 和 Container 之间的 CUDA 相关的链接,让你可以直接在 Container 里面使用 GPU。

Ubuntu 18.04 安装 Docker CE 及 nvidia-docker2 流程

安装环境

  • OS:Ubuntu 18.04 64 bit
  • 显卡:NVidia GTX 1080
  • CUDA:10.0
  • cnDNN:7.4

任务:安装 Docker CEnvidia-docker2,以便后期开展深度学习

配置 Docker 源

# 更新源
$ sudo apt-get update

# 启用 HTTPS
$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

# 添加 GPG key
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

# 添加稳定版的源
$ sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

安装 Docker CE

# 更新源
$ sudo apt-get update

# 安装 Docker CE
$ sudo apt-get install docker-ce

如果这种方式安装失败,也有解决方案。
报错时屏幕上会显示下载失败的 deb 文件,想办法 下载下来,然后挨个手动安装就好。

此时我需要下载的是下面三个文件:

  • containerd.io_1.2.2-1_amd64.deb
  • docker-ce-cli_18.09.1~3-0~ubuntu-bionic_amd64.deb
  • docker-ce_18.09.1~3-0~ubuntu-bionic_amd64.deb

手动依次安装:

$ sudo dpkg -i containerd.io_1.2.2-1_amd64.deb
$ sudo dpkg -i docker-ce-cli_18.09.1~3-0~ubuntu-bionic_amd64.deb
$ sudo dpkg -i docker-ce_18.09.1~3-0~ubuntu-bionic_amd64.deb

验证 Docker CE

如果出现下面的内容,说明安装成功。

$ sudo docker run hello-world

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete 
Digest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

配置 nvidia-docker2

# 添加源
$ curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
$ distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
$ curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | \
  sudo tee /etc/apt/sources.list.d/nvidia-docker.list

安装nvidia-docker2

# 安装 nvidia-docker2
$ sudo apt-get install -y nvidia-docker2

# 重启 Docker daemon
$ sudo pkill -SIGHUP dockerd

验证nvidia-docker2

$ sudo nvidia-docker run --rm nvidia/cuda nvidia-smi

能看到显卡信息就说明 OK 了,当前 image 是基于 Ubuntu 18.04 的。

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计2415字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中