admin管理员组文章数量:1564172
win10 docker部署gpu项目
- nvidia-docker
- win10安装docker
- 制作镜像
- ubuntu18.04部署docker gpu项目
- 安装docker
- 配置docker使用gpu
- bug
nvidia-docker
nvidia-docker是一个可以使用GPU的docker,nvidia-docker是在docker上做了一层封装,通过nvidia-docker-plugin,然后调用到docker上,其最终实现的还是在docker的启动命令上携带一些必要的参数。因此在安装nvidia-docker之前,还是需要安装docker的。
hi,这是我用百度网盘分享的文件~复制这段内容打开「百度网盘」APP即可获取。
链接:https://pan.baidu/s/1Wd3tK1CaJnSEet1oTXZK0w
提取码:b4
hi,这是我用百度网盘分享的文件~复制这段内容打开「百度网盘」APP即可获取。
链接:https://pan.baidu/s/1VASxh9K7vOCH_cVLQUBk7A
提取码:DK5R
docker一般都是使用基于CPU的应用,而如果是GPU的话,就需要安装特有的硬件环境,比如需要安装nvidia driver。所以docker容器并不直接支持Nvidia GPU。为了解决这个问题,最早的处理办法是在容器内部,全部重新安装nvidia driver,然后通过设置相应的设备参数来启动container,然而这种办法是很脆弱的。因为宿主机的driver的版本必须完全匹配容器内的driver版本,这样导致docker image无法共享,很可能本地机器的不一致导致每台机器都需要去重复操作,这很大的违背了docker的设计之初。
为了使docker image能很便利的使用Nvidia GPU,从而产生了nvidia-docker,由它来制作nvidia driver的image,这就要求在目标机器上启动container时,确保字符设备以及驱动文件已经被挂载。
nvidia-docker-plugin是一个docker plugin,被用来帮助我们轻松部署container到GPU混合的环境下。类似一个守护进程,发现宿主机驱动文件以及GPU 设备,并且将这些挂载到来自docker守护进程的请求中。以此来支持docker GPU的使用。
参考:
安装使用NVIDIA-Docker-- 可使用GPU的Docker容器
Docker运行GPU环境只需几步
docker用gpu的参数
docker使用GPU总结
ubuntu Docker完全卸载
nvidia-smi 报错:无法与 nvidia driver 通信
win10安装docker
-
下载 Docker Desktop Installer
-
在win10上打开hyper-v
-
按步骤安装
-
最终打开为
制作镜像
新建一个文件夹后项目整体放入,添加dockerfile和requirements.txt
-
Dockerfile
# 基于镜像基础 FROM cryptoandcoffee/nvidia-docker-cuda-10-base # 设置代码文件夹工作目录 /test WORKDIR /test # 复制当前代码文件到容器中 /test ADD . /test # 安装所需的包 # RUN pip install -r requirements.txt # Run test.py when the container launches # CMD ["python", "test.py"]
-
requirements.txt
-
新建镜像:使用当前目录的 Dockerfile 创建镜像,标签为 htagpu:v1,注意最后有个点
docker build -t htagpu:v1 .
-
查看镜像
docker images
-
在镜像中建立容器
docker run -dit --name main 镜像id /bin/bash
-
进入容器
docker exec -it 容器id /bin/bash
-
容器内安装vim
apt-get update apt-get install vim
-
容器内安装python
在容器里面安装python3、pip 注意系统版本问题: 如果是 centos 那即是 yum 如果是 ubuntu 那即是 apt-get 如果是 alpine 那即是 apk 如下是apt安装python3(ubuntu) #先更新软件源 apt-get update apt-get install -y python3 apt install -y python3-pip
-
查看容器内是否有nvidia驱动
nvidia-smi
-
测试能否调用gpu
import tensorflow as tf tf.contrib.eager.num_gpus() import torch print(torch.__version__) print(torch.cuda.is_available())
ubuntu18.04部署docker gpu项目
安装docker
-
安装需要的包
sudo apt-get update
-
安装 apt 依赖包,用于通过HTTPS来获取仓库
sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg-agent \ software-properties-common
-
添加 Docker 的官方 GPG 密钥
curl -fsSL https://download.docker/linux/ubuntu/gpg | sudo apt-key add -
-
设置稳定版仓库
sudo add-apt-repository \ "deb [arch=amd64] https://download.docker/linux/ubuntu \ $(lsb_release -cs) \ stable"
-
安装 Docker-ce
sudo apt-get update sudo apt-get install docker-ce docker-ce-cli containerd.io
-
设置开机自启动并启动 Docker-ce,安装成功后默认开启,可忽略该步骤
-
测试运行
```bash sudo docker run hello-world ```
-
添加当前用户到 docker 用户组
# 列出自己的用户组,确认自己在不在 docker 组中 groups # 没有则新增docker组 sudo groupadd docker # 把当前用户加入到docker组中 sudo gpasswd -a ${USER} docker # 更新用户组 newgrp docker
配置docker使用gpu
-
关于配置docker19使用gpu,其实只用装官方提供的toolkit即可,把github上的搬下来:
Ubuntu 16.04/18.04, Debian Jessie/Stretch/Buster:# Add the package repositories 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 sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit sudo systemctl restart docker
-
测试安装是否成功
docker run --help | grep -i gpus --gpus gpu-request GPU devices to add to the container ('all' to pass all GPUs)
-
运行nvidia官网提供的镜像,并输入nvidia-smi命令,查看nvidia界面是否能够启动:
docker run --gpus all nvidia/cuda:9.0-base nvidia-smi
-
运行容器:
docker run --gpus all -dit --name=main id /bin/bash docker run -dit --gpus all --name=main bfa /bin/bash
-
进入容器:
docker exec -it id /bin/bash
-
查看容器版本:
cat /etc/issue
-
安装显卡驱动
https://blog.csdn/zaf0516/article/details/103565262
Ubuntu18.04LTS 换源
https://www.jianshu/p/97c35d569aa3 -
安装python3.8
ubuntu16.04 安装python3.6踩坑
https://blog.csdn/qq_42693848/article/details/88900553报错:
E: Unable to locate package python3.6-dev
E: Couldn’t find any package by glob ‘python3.6-dev’
E: Couldn’t find any package by regex ‘python3.6-dev’apt-get update apt -y upgrade apt -y autoremove apt-get install vim apt -y install python3.8 # 删除旧的软连接 rm -rf /usr/bin/python3 rm -rf /usr/bin/pip3 # 新增新的软连接 # 获取软连接位置 pythonpath=`which python3.8` # 添加python3的软链接 ln -s $pythonpath /usr/bin/python # 添加 pip3 的软链接,先要添加软连接在安装pip pippath=`which pip` ln -s $pippath /usr/bin/pip # 添加3.8版本的apt_pkg cd /usr/lib/python3/dist-packages cp apt_pkg.cpython-36m-x86_64-linux-gnu.so apt_pkg.cpython-37m-x86_64-linux-gnu.so # 测试是否安装成功了 python3 --version
-
安装pip
apt-get update apt-get install python3-pip # 进行升级 python -m pip install --upgrade pip
-
复制项目到容器内
新建一个terminol docker cp . main:/test 回到容器内cd 到 test
-
装环境
https://pytorch/get-started/previous-versions/
pip install torch==1.5.0 torchvision==0.6.0
pytorch环境,单独装:
```bash
pip install torch==1.5.0+cu101 torchvision==0.6.0+cu101 -f https://download.pytorch/whl/torch_stable.html
```
直接pip install -r requirements.txt
```
atomicwrites==1.3.0
attrs==19.3.0
colorama==0.4.3
easydict==1.9
entrypoints==0.3
et-xmlfile==1.0.1
flake8==3.7.9
flake8-import-order==0.18.1
importlib-metadata==1.6.0
jdcal==1.4.1
joblib==0.14.1
lap==0.4.0
mccabe==0.6.1
more-itertools==8.2.0
motmetrics==1.2.0
numpy==1.18.2
opencv-python==4.2.0.34
openpyxl==3.0.3
packaging==20.3
pandas==1.0.3
Pillow==7.1.1
pluggy==0.13.1
py==1.8.1
py-cpuinfo==5.0.0
pycodestyle==2.5.0
pyflakes==2.1.1
pyparsing==2.4.7
pytest==5.4.1
pytest-benchmark==3.2.3
python-dateutil==2.8.1
pytz==2019.3
PyYAML==5.3.1
scikit-learn==0.22.2.post1
scipy==1.4.1
six==1.14.0
sklearn==0.0
Vizer==0.1.5
wcwidth==0.1.9
xmltodict==0.12.0
zipp==3.1.0
requests==2.26.0
```
-
运行test报错
root@59a8688f22de:/test# python test.py Traceback (most recent call last): File "test.py", line 1, in <module> import HighTossAct as hta File "/test/HighTossAct.py", line 4, in <module> import cv2 File "/usr/local/lib/python3.8/dist-packages/cv2/__init__.py", line 5, in <module> from .cv2 import * ImportError: libXrender.so.1: cannot open shared object file: No such file or directory
解决Ubuntu安装opencv报ImportError错误,cannot open shared object file: No such file or directory
缺少必要的静态库
先安装apt-file。
apt-get update
apt-get install apt-file
apt-file update然后寻找该依赖库:
apt-file search libXrender.so.1
根据提示安装合适的依赖库:
apt-get install libxrender1
基本上所有的“ cannot open shared object file: No such file or directory”错误都可以这么解决。
-
运行不报错后打包镜像
docker save和docker export的区别
对于Docker Save方法,会保存该镜像的所有历史记录
对于Docker Export 方法,不会保留历史记录,即没有commit历史
docker save保存的是镜像(image),docker export保存的是容器(container);
docker load用来载入镜像包,docker import用来载入容器包,但两者都会恢复为镜像;
docker load不能对载入的镜像重命名,而docker import可以为镜像指定新名称。docker save -o main.tar bfa
使用docker export直接打包容器,之后导入容器使用docker import
bug
时区设置,重新启动一个容器,加上如下参数,即可使用宿主机时间
docker run -dit -v /etc/localtime:/etc/localtime:ro --name=main1 e3fb /bin/bash
docker run -itd --gpus all --name main5 -v /etc/localtime:/etc/localtime:ro -e NVIDIA_DRIVER_CAPABILITIES=video,compute,utility -e NVIDIA_VISIBLE_DEVICES=all d19 /bin/bash
链接: https://pan.baidu/s/1KAjESUTJMrgvHE6i7YVKIg 密码: k69t
–来自百度网盘超级会员V1的分享
版权声明:本文标题:win10 docker部署gpu项目 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dongtai/1727483688a1117011.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论