1、参考博客
1、docker的安装使用,及打包深度学习环境【很详细】
2、Docker打包深度学习项目(解决:Opencv依赖库、共享内存)
3、Docker 镜像构建之 Dockerfile
4、Docker深度学习环境安装、部署、打包
5、使用conda pack进行环境迁移(步骤很详细)
6、使用nvidia-docker创建gpu支持深度学习环境的容器
2、 普通Docker和NVIDIA Docker安装
不同平台的Docker安装方式可以参考官方文档(Docker Install) ,我这里就用Ubuntu系统作为例子。
1、Install Docker Engine on Ubuntu
# Docker
#在首次在新的主机上安装Docker Engine之前,需要设置Docker存储库。之后,您可以从存储库中安装和更新Docker。
#1、更新apt包索引并安装包,以允许apt通过HTTPS使用存储库:
$ sudo apt-get update
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
#2. 添加Docker的官方GPG密钥:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
#添加docker官方gpg密钥,这里改成中科大镜像的
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
#3、使用以下命令设置存储库:
$ sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
#设置稳定版本库,也换成中科大的
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/ \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Docker engine,安装docker,默认是安装最新版
#1. 更新apt包索引,安装最新版本的Docker Engine、containd和Docker Compose,或者执行下一步安装具体版本:
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
在完成安装后,执行下面命令,以确保安装成功:
sudo docker run hello-world
执行后看到打印出来正常的提示信息则表示安装成功。
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:10d7d58d5ebd2a652f4d93fdd86da8f265f5318c6a73cc5b6a9798ff6d2b2e67
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
7. 卸载
sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-compose-plugin
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
输入指令: docker version或者docker -v
然后启动,输入指令:systemctl start docker
输入指令:systemctl status docker 查看状态
设置开机自启动
输入指令:systemctl enable docker
2、安装NVIDIA Docker。
详细安装步骤见NVIDIA Docker Installation Guide. 安装完记得重启Docker,并用nvidia/cuda:11.0-base这个默认容器测试一下是否安装成功。
1、Setting up Docker
在更新包清单后安装nvidia-docker2包(和依赖项):
curl https://get.docker.com | sh \
&& sudo systemctl --now enable docker
sudo apt-get update
sudo apt-get install -y nvidia-docker2
2、重启docker
查看docker镜像
nvidia-docker image ls
sudo systemctl restart docker
sudo docker run --rm --gpus all nvidia/cuda:10.2-devel nvidia-smi

sudo docker run --rm --gpus all nvidia/cuda:11.0.3-base-ubuntu20.04 nvidia-smi
# Restart the Docker daemon to complete the installation after setting the default runtime:
sudo systemctl restart docker
sudo docker run --rm --gpus all nvidia/cuda:11.0-base nvidia-smi
# 出现显卡信息界面即为安装成功
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 450.51.06 Driver Version: 450.51.06 CUDA Version: 11.0 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M.

本文详细介绍如何使用Docker打包深度学习环境,包括安装Docker和NVIDIA Docker、创建Dockerfile、构建镜像、运行和测试镜像的过程。此外,还介绍了如何使用PyInstaller将Python项目打包成可执行文件。
9313

被折叠的 条评论
为什么被折叠?



