1、安装nvidia-docker基础镜像(官网拉取,选定自己版本)
docker run --runtime=nvidia --rm nvidia/cuda:9.0-base nvidia-smi
docker run --runtime=nvidia --rm nvidia/cuda:10.0-base nvidia-smi
docker run --runtime=nvidia --rm nvidia/cuda:10.1-base nvidia-smi
docker run --runtime=nvidia --rm nvidia/cuda:11.2-base nvidia-smi
默认下载基础镜像,并启动容器测试,是否成功(安装了nvida-docker2才行,不然会报错没有运行时)(pull手动拉取)
docker pull-nvidia/cuda:9.0-base
2、查看基础镜像,启动成容器
REPOSITORY TAG IMAGE ID CREATED SIZE
nvidia/cuda 10.1-base bfa75f8b799e 3 days ago 105MB
启动容器:sudo docker run -itd --name qinghao nvidia/cuda:10.1-base /bin/bash
进入容器:sudo docker attach qinghao
低版本+需要安装nvidia-docker2才能执行上述命令
docker-19.03及以上版本已经集成了nvidia-docker,但是启动命令变了,需要指定gpu不然不行
docker run -it --gpus all --rm --name test nvida/cuda:10.1-base /bin/bash
3、换源(/etc/apt/sources.list)
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
4、你会发现打不开,vim不好使用。外面新建一个文件,拷进去。
docker cp 外路径 容器:内路径
sudo docker cp sources.list qinghao:/etc/apt/
5、apt update ---------更新
6、但是会卡壳怎么办?
cd /usr/lib/apt/methods
ln -s http https
apt update
7、安装conda
wget https://repo.continuum.io/archive/Anaconda3-5.2.0-Linux-x86_64.sh
bash Anaconda3-5.2.0-Linux-x86_64.sh
配置系统变量
vim /etc/bash.bashrc
export PATH="/root/anaconda3/bin:"$PATH
source /etc/bash.bashrc
8、发现没有wget
apt install wget
9、运行程序可以,但是没有中文语言包
apt-get install language-pack-zh-han*
export LANGUAGE=zh_CN.UTF-8
export LANG=zh_CN.UTF-8
export LC_ALL=zh_CN.UTF-8
10、缺什么环境就一系列安装就行了
11、容器封装成镜像(下次用这个基镜像FROM,docker build就行了)
sudo docker export qinghao > qinghao-base.tar
12、加载
docker import qinghao-base.tar cuda_python
11&12、是一个错误的步骤
发现不能export和import,但是使用commit可以解决问题
sudo docker commit qinghao cuda_python
再来一个Dockerfile
FROM cuda_python
ENV PATH /usr/local/bin:$PATH
ENV PATH /root/anaconda3/bin/:$PATH
WORKDIR /code
RUN pip install -i https://pypi.doubanio.com/simple/ --upgrade pip
RUN pip install -i https://pypi.doubanio.com/simple/ tensorflow-gpu==2.2.2
RUN pip install -i https://pypi.doubanio.com/simple/ sklearn
RUN pip install -i https://pypi.doubanio.com/simple/ tqdm
RUN pip install -i https://pypi.doubanio.com/simple/ Keras==2.3.1
RUN pip install -i https://pypi.doubanio.com/simple/ bert4keras==0.10.6
13、可能会出现cudnn不存在,安装一个即可
conda install -c anaconda cudnn==7.6.4 --yes