ubuntu配置docker, nvidia-container-toolkit

   最近调试代码需要低版本的nvcc和gcc,但是系统版本已经是最新的了,又不想把系统整体的配置降低,conda也只能解决python等版本的问题没法解决这个问题
  docker的好处在于其基于宿主机(也就是我们远程的服务器,是一个物理机)可以任意搭配你想要的各种环境,而不用对宿主机的环境产生影响,所以在网上学了很久docker,也折腾了很久,终于弄好了,做个笔记,便于自己理解,也便于和我一样的小白可以入手docker

配置docker

  首先可以参考官方教程: 点击链接

个人总结:

# 更新源
$ sudo apt update

# 启用HTTPS
$ sudo apt install -y \
    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 update

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

测试Docker CE

输入:sudo docker run hello-world

$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete 
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
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-container-toolkit

  首先可以参考官方教程:点击链接

个人总结

# 添加源
$ distribution=$(. /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.list

# 安装并重启docker
$ sudo apt update && sudo apt install -y nvidia-container-toolkit
$ sudo systemctl restart docker

测试nvidia-container-toolkit

# 在官方CUDA镜像上测试 nvidia-smi
$ sudo docker run --gpus all --rm nvidia/cuda:11.0-base nvidia-smi

# 启动支持双GPU的容器
$ sudo docker run --gpus 2 --rm nvidia/cuda:11.0-base nvidia-smi

# 指定指定GPU 0,1,运行容器
$ sudo docker run --gpus device='"0,1"' --rm nvidia/cuda:11.0-base nvidia-smi

若出现GPU信息,则代表成功,如下图:

在这里插入图片描述

nvidia/cuda:9.0-base个人理解是nvidia下的cuda9.0基础版的镜像

还有很多用法在官网教程里点击链接,基本满足我们的需求了

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值