Centos 安装nvidia-docker并用anaconda安装pytorch、mxnet

安装docker,首先要确保是centos7版本

docker安装

第一步:Uninstall old versions
如果老版本的docker或者docker-engine被安装,我们需要卸载他们,连同与其关联的其他依赖。

$ sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
It’s OK if yum reports that none of these packages are installed.

The contents of /var/lib/docker/, including images, containers, volumes, and networks, are preserved. The Docker Engine - Community package is now called docker-ce.

第二步:Install using the repository
$ sudo yum install -y yum-utils \
device-mapper-persistent-data\
lvm2

用下面的指令建立一个稳态仓库
$ sudo yum-config-manager \
–add-repo \
https://download.docker.com/linux/centos/docker-ce.repo

第三步:INSTALL DOCKER ENGINE - COMMUNITY
安装最新版本的docker以及容器
$ sudo yum install docker-ce docker-ce-cli containerd.io

If prompted to accept the GPG key, verify that the fingerprint matches 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35, and if so, accept it.

第四步:Start Docker
$ sudo systemctl start docker

第五步:Verify Docker Engine - Community
$ sudo docker run hello-world

如果verify的过程中出现错误,需要注意服务器的代理设置
$ mkdir -p /etc/systemd/system/docker.service.d
创建/etc/systemd/system/docker.service.d/http-proxy.conf文件,并添加HTTP_PROXY环境变量。其中[proxy-addr]和[proxy-port]分别改成实际情况的代理地址和端口。

如果没有proxy代理,将文件内填入
[Service]
Environment=“NO_PROXY=localhost,127.0.0.1,mydocker-registry:5000”
应该就没问题了。

更新配置:
$ systemctl daemon-reload
重启Docker服务
$ systemctl restart docker

nvidia-docker

# 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
     
    # Install nvidia-docker2 and reload the Docker daemon configuration
    sudo yum install -y nvidia-docker2
    sudo pkill -SIGHUP dockerd
     
    # Test nvidia-smi with the latest official CUDA image
    docker run --runtime=nvidia --rm nvidia/cuda:10.0-base nvidia-smi

可以使用阿里云的源对docker镜像下载加速,具体步骤阿里云官网有,不多赘述。

如果运行不了,可以试试以下方法
sudo tee /etc/docker/daemon.json
<<EOF
{
“runtimes”:{
“nvidia”:[
“path”:
“/usr/bin/nvidia-container-runtime”,
“runtimeArgs”:
[]
}
}
}
EOF

sudo pkill -SIGHUP dockerd

sudo nvidia-docker run -it nvidia/cuda:9.0-base
拉cuda9.0的容器并运行,如果成功,可以在docker里sudo nvidia-smi。
这样nvidia-docker就成功安装了。

anaconda

在docker容器中是没有yum等指令的,我们需要通过apt-get install yum去安装。
下载地址https://www.anaconda.com/download/
在root下 $ bash Anaconda3-4.4.0-Linux-x86_64.sh
或者通过清华源 wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-5.3.1-Linux-x86_64.sh

如何使用清华源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes

pip install xxx -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com
pip加镜像操作

安装完后增加环境变量

vim /root/.bashrc

# added by Anaconda3 4.4.0 installer
export PATH="/root/anaconda3/bin:$PATH"

保存后
source /root/.bashrc

如果没有root权限,可以 bash vim /home/xxx/.bashrc,
export PATH="/home/xxx/anaconda3/bin:$PATH"
验证conda list

在安装环境前,我们可以更换清华源,这里不赘述,但要注意在更改源之后,一定要将docker restart再进入容器才起作用

conda create -n your name python=xx
source activate your name
deactivate
conda install

pytorch

安装pytorch就很简单了,直接去官网找到指令,conda install 就ok了。
conda install pytorch torchvision cudatoolkit=10.1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值