docker 建立容器 - tensorflow & pytorch 记录

建立目的是准备一个有基本环境的docker镜像,这样在配置以后对应环境的时候就会省点心
base环境有
vim
g++
conda
ssh

base_p 环境是python的深度学习环境
cuda
cudnn
pytorch
tensorflow
opencv/ contrib

base

su
docker run --gpus all -it  -p 1212:22 -v /home:/home --name='base_' 3c2 /bin/bash
# 这里的3c2是nvidia的官方镜像,但最好是devel版,有nvcc

# 参考https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/ 换源
apt-get update
apt-get install -y vim
apt-get install -y g++

vi /etc/apt/sources.list 

#安装miniCONDA https://docs.conda.io/en/latest/miniconda.html#linux-installers
apt-get update
apt-get upgrade 
apt-get install -y wget
mkdir temp && cd temp
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
# 在这里,如果你需要通过vs code调用你的conda环境,请不要安装在/root下,因为vs code没有访问root的权限
# 重启容器
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/

# ssh安装
passwd
apt-get install openssh-server
apt-get install openssh-client
# 配置ssh服务
sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
echo "export VISIBLE=now" >> /etc/profile


# 加入PermitRootLogin yes #允许root用户使用ssh登录
service ssh restart

# 容器外测试映射
docker port <your container name> 1212
ssh root@<你服务器的ip地址> -p 1212

python : tensorflow pytorch

# 基于上面建立的base镜像
conda install cudatoolkit=11.2
conda install cudnn=8
# https://pytorch.org/
pip3 install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html
pip3 install tensorflow -i https://pypi.tuna.tsinghua.edu.cn/simple some-package
# opencv
pip install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple some-package #清华源
pip install opencv-python-contrib -i https://pypi.tuna.tsinghua.edu.cn/simple some-package #清华源
#########
#如果在装opencv时遇到了NoneType 的错误,可以指定opencv的版本来避免
#如果不想安装opencv的一些依赖,可以安装opencv-python-headless
#清华源:-i https://pypi.tuna.tsinghua.edu.cn/simple
#########

issue1 ffi 这个已经在收藏夹里了
issue2 arch的问题,删掉30那个
issue3 setuptools的问题:TypeError: dist must be a Distribution instance 解决:cuda版本降低

pip3 install torch0.4.1 torchvision0.2.1 -f https://download.pytorch.org/whl/torch_stable.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值