安装Docker及配置GPU版本的docker

您所在的位置:网站首页 ubuntu安装docker18 安装Docker及配置GPU版本的docker

安装Docker及配置GPU版本的docker

2023-12-11 08:44| 来源: 网络整理| 查看: 265

在深度学习过程中,我们用到各种框架,如tensorflow\pytorch\mxnet\caffe等,除了使用虚拟环境来配置这些环境以外,还有一种方法就是docker了。

docker是一个很强大的工具,不了解的可自行Google,很多教程,这里附上官方文档:https://docs.docker.com/

下面介绍几个docker的名词:

image: 就是镜像,是别人或自己做好的机器学习的环境,只要pull下来就可以了。container: 也叫容器,是docker根据镜像产生的,一个镜像可以产生多个容器。我们的代码运行实际上是在容器中。容器中也可以装这种软件但容器停止运行后并不会提交到镜像中,如果要保存这些改变可以使用commiting指令(这里我也没有仔细研究)。deamon: daocker守护进程,当安装完docker并启动后docker守护进程就开始运行,用来管理镜像、容器等。可以通过docker API和socket两种方式与deamon进行交互。  

因为本人正好需要使用MXnet,因此以此框架进行介绍:

安装docker

如果系统的ubuntu,则根据https://docs.docker.com/install/linux/docker-ce/ubuntu/安装docker,EE或CE版本可以自行选择。

其它系统,可以根据网页左侧导航栏自行选择。

安装完成后,运行

sudo docker run hello-world

如果可以,那说明安装成功了,此时我们注意到每次运行时,都需要以sudo获取权限,这是因为docker默认的是root用户啊,为了方便,我们可以采用下面方式来获取docker运行权限。

修改权限链接:https://docs.docker.com/install/linux/linux-postinstall/

安装nvidia-docker

在深度学习中,我们用到的必不可少的便是GPU运算了,因此我们需要安装nvidia-docker,来确保可以进行GPU运算。

ps:当然你的电脑必须支持GPU运算,并安装了cuda和cudnn

我们可以从github上,获取安装方式,链接如下:https://github.com/NVIDIA/nvidia-docker/wiki/Installation-%28version-2.0%29

方法很简单,安装教程,问题不大,这里说一下出现的几个问题。

问题一: docker volume ls -q -f driver=nvidia-docker | xargs -r -I{} -n1 docker ps -q -a -f volume={} | xargs -r docker rm -f sudo apt-get purge nvidia-docker # 这一步容易出现找不到nvidia-docker的问题

解决办法:

如果是Ubuntu 14.04/16.04, Debian Jessie/Stretch系统:

# Add the package repositories 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 sudo apt-get update

如果是CentOS 7, RHEL 7.4, Amazon Linux 2:

# Add the package repositories distribution=$(. /etc/os-release;echo $ID$VERSION_ID) curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.repo | \ sudo tee /etc/yum.repos.d/nvidia-docker.repo

 

问题二:

在安装nvidia-docker2时遇到:

user08@lthpc:~$ sudo apt-get install -y nvidia-docker2=2.0.3+docker18.09.7-3 nvidia-container-runtime=2.0.0+docker18.09.7-3 Reading package lists... Done Building dependency tree Reading state information... Done Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation: The following packages have unmet dependencies: nvidia-docker2 : Depends: docker-ce (= 5:18.09.7~3-0~ubuntu-xenial) but 5:19.03.1~3-0~ubuntu-xenial is to be installed or docker-ee (= 5:18.09.7~3-0~ubuntu-xenial) but it is not installable

解决办法:

sudo apt-get install docker-ce=5:18.09.0~3-0~ubuntu-xenial #更新报错括号里的内容

另外建议:不要直接安装nvidia-docker2的最新版,因为你的机器不一定支持,我们可以通过下面程序:

apt-cache madison nvidia-docker2 nvidia-container-runtime or yum search --showduplicates nvidia-docker2 nvidia-container-runtime

来查看支持的版本,然后通过下面命令来安装:

sudo apt-get install -y nvidia-docker2=2.0.1+docker1.12.6-1 nvidia-container-runtime=1.1.0+docker1.12.6-1 #注意一定要同时指定nvidia-docker2和nvidia-container-runtime的版本

问题三:

如果运行nvidia-docker出错,说明你可能没有注册,

docker: Error response from daemon: Unknow runtime specified nvidia.

解决办法:https://blog.csdn.net/weixin_32820767/article/details/80538510

最后一步,拉取MXnet docker 镜像 docker pull mxnet/python:gpu #安装完成后,运行下面指令即可运行: nvidia-docker run -it mxnet/python:gpu bash

如果拉取镜像速度太慢,或者Timeout,可以先修改docker的镜像源。

 

本文参考:https://blog.csdn.net/ryanpinwei/article/details/78806052



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3