1、安装docker
- 配置docker镜像
添加镜像源至docker engine
2、wsl2安装nvidia-docker
要在Ubuntu中安装NVIDIA Docker,需要满足以下条件:
- 确保主机已安装NVIDIA的CUDA驱动程序,并使用适用于您操作系统的正确版本。
wsl --update
在Ubuntu中安装NVIDIA Docker的步骤如下:
- 确认系统已安装并正常工作Docker。如果未安装Docker,请先进行安装。
- 在终端中,运行以下命令添加NVIDIA Docker的apt仓库密钥:
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
- 添加apt仓库。创建一个新的apt源文件,并将"main"和"stable"组件添加到文件中:
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
- 更新apt缓存并安装nvidia-docker2包:
sudo apt-get update
sudo apt-get install -y nvidia-docker2
- 安装完成后,重启Docker服务:
sudo systemctl restart docker
- 使用以下命令检查是否正确安装了nvidia-docker2:
docker run --gpus all nvidia/cuda:11.0-base nvidia-smi
运行此命令应该成功运行容器内的nvidia-smi命令,并显示GPU信息。如果一切正常,说明成功在Ubuntu中安装了NVIDIA Docker。
3、复现pytorch_cyclegan
(1) 构建DockerFile文件,写入语句
FROM nvidia/cuda:11.1.1-cudnn8-runtimeRUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/3bf863cc.pub# 更新apt索引并安装所需工具
RUN apt update && apt install -y wget unzip curl bzip2 git
RUN curl -LO http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.shRUN bash Miniconda3-latest-Linux-x86_64.sh -p /miniconda -b
RUN rm Miniconda3-latest-Linux-x86_64.sh
ENV PATH=/miniconda/bin:${PATH}
RUN conda update -y conda# 创建新的conda环境并安装特定版本的pytorch和torchvision
RUN conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
RUN conda config --set show_channel_urls yes# 设置环境变量
ENV PATH="/opt/conda/bin:$PATH"
# RUN /opt/conda/bin/conda run -n cycle pip install torch==1.10.0+cu111 torchvision==0.11.0+cu111 torchaudio==0.10.0 -f https://download.pytorch.org/whl/torch_stable.html
# 激活环境并安装其他依赖
RUN mkdir /workspace/ && cd /workspace/ && git clone https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix.git \&& cd pytorch-CycleGAN-and-pix2pix# 设置工作目录
WORKDIR /workspace
(2)存放至目录下便于构建
app
├── app/Dockerfile
├── app/app.py
└── app/requirements.txt
(3)运行命令构建镜像
进入app目录,
docker build -t [镜像名] .
# 假设我们有一个名为 my-base-image:latest 的本地镜像
docker build --build-arg BASE_IMAGE=my-base-image:latest -t my-app .
(4)根据镜像建立容器,在容器中安装对应的包
docker run -it --name [容器名] [镜像名] /bin/bash
待选步骤:
(5)安装包之后构建好了新的容器,commit提交存至新的镜像
docker commit -m "xx" [容器名] [镜像名]
(6)后面只需直接拉取镜像,并创建容器,就可直接运行
docker run --gpus all -it --name [容器名] [镜像名] /bin/bash
# 部分docker语句记录
docker run --gpus all -it --name yolov8_mount -v E:\BaiduNetdiskDownload\VOC07+12+test\VOCdevkit:/root/yolov8-pytorch/ --cpus="2.0" 7c69963d2d79:latest bashdocker run --gpus all -it --name yolov8_mount -v E:\BaiduNetdiskDownload\VOC07+12+test\VOCdevkit:/root/yolov8-pytorch/ --cpuset-cpus="0,1" 7c69963d2d79:latest bash
4、 已构建好的镜像参考
docker pull lin0011/cyclegan
参考链接:
1、【K8S】docker打过tag标签后向镜像仓库推送镜像(push)
https://blog.csdn.net/m0_45406092/article/details/103963974
2、Index of /compute/cuda/repos/ubuntu2004/x86_64
https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/
3、nvidia/cuda:11.1.1-cudnn8-runtime
https://hub.docker.com/r/nvidia/cuda/tags?ordering=-last_updated
4、docker:machine learning
https://hub.docker.com/search?categories=Machine+Learning+%26+AI&page=3
5、CUDA Toolkit 11.1 Update 1 Downloads
https://developer.nvidia.com/cuda-11.1.1-download-archive?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=2004&target_type=debnetwork
6、官方源码:
https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix.git
7、如何指定dockerfile中From后的基础镜像从本地获取https://blog.csdn.net/muwan2900/article/details/139737060?spm=1001.2014.3001.5506
8、极智开发 | gpu docker启动报错libnvidia-ml.so.1: file exists: unknown
https://zhuanlan.zhihu.com/p/652588664
9、Visual Studio 的粘滞滚动功能是什么?
https://learn.microsoft.com/zh-cn/visualstudio/ide/editor-sticky-scroll?view=vs-2022