孝感网站建设效果,哈尔滨网站建设教学,呼和浩特网络运营,外贸公司推广平台文章目录 安装docker创建镜像创建容器 合作推广#xff0c;分享一个人工智能学习网站。计划系统性学习的同学可以了解下#xff0c;点击助力博主脱贫( •̀ ω •́ )✧ 使用docker的好处就是可以将你的环境和别人的分开#xff0c;特别是共用的情况下。本文介绍了ubuntu环境… 文章目录 安装docker创建镜像创建容器 合作推广分享一个人工智能学习网站。计划系统性学习的同学可以了解下点击助力博主脱贫( •̀ ω •́ )✧ 使用docker的好处就是可以将你的环境和别人的分开特别是共用的情况下。本文介绍了ubuntu环境下创建pytorch-gpu的教程centos其实也是差不多的。
安装docker 首先是安装docker
sudo apt-get update # 更新软件包
# 安装必要的依赖
sudo apt install apt-transport-https ca-certificates curl software-properties-common
sudo apt-get install docker
# 添加 Docker GPG 密钥
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
# 设置 Docker 存储库
echo deb [archamd64 signed-by/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable | sudo tee /etc/apt/sources.list.d/docker.list /dev/null
# 安装docker
sudo apt install docker-ce docker-ce-cli containerd.io
# 授权sudo
sudo usermod -aG docker $USER使用以下代码检查安装成功与否
dockcer --version创建镜像 首先是新建一个目录你找得到就可名字叫什么都行
mkdir /wzl
cd /wzl然后是准备两个文件一个镜像源一个Dockerfile。
镜像源 新建文件source.list
sudo vim source.list然后复制以下代码华为源使用其他国内源都可
deb https://repo.huaweicloud.com/ubuntu/ focal main restricted
deb https://repo.huaweicloud.com/ubuntu/ focal-updates main restricted
deb https://repo.huaweicloud.com/ubuntu/ focal universe
deb https://repo.huaweicloud.com/ubuntu/ focal-updates universe
deb https://repo.huaweicloud.com/ubuntu/ focal-backports main restricted universe
deb https://repo.huaweicloud.com/ubuntu/ focal-security main restricted
deb https://repo.huaweicloud.com/ubuntu/ focal-security universe
deb http://archive.ubuntu.com/ubuntu/ trusty main universe restricted multiverse vim先按Esc然后输入:wq回车保存退出生怕你们linux不好(doge。 插播反爬信息 博主CSDN地址https://wzlodq.blog.csdn.net/ Dockerfile 新建Dockerfile文件
sudo vim Dockerfile复制以下代码
FROM pytorch/pytorch:1.11.0-cuda11.3-cudnn8-runtimeMAINTAINER yyqENV DEBIAN_FRONTENDnoninteractive
#更新pip并且换源
RUN pip install pip -U # 升级pip到最新版本
RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple#为了运行apt-get update
RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak
COPY sources.list /etc/apt/sources.list
RUN chmod ax /etc/apt/sources.list#更新apt
RUN apt-get update
#安装依赖
RUN apt-get install gcc -y apt-get install make -y \ apt-get install vim -y apt-get install openssl -y \ apt-get install libssl-dev -y apt-get install python3-pip -yRUN apt-get install vim ffmpeg libsm6 libxext6 cron openssh-server -y
# 为防止安装依赖太长需要换行直接用两行 pip install, 不会出现下面一行的依赖没有安装
RUN pip install aio-pika7.1.0 asyncio3.4.3 APScheduler3.7.0 matplotlib3.3.4 opencv-python4.5.2.52
RUN pip install pandas1.5.3 pyyaml6.0 tqdm4.64.1 seaborn0.12.2
RUN pip install Pillow8.2.0 pika1.2.0 pymongo3.11.4 requests2.25.1RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime echo Asia/Shanghai/etc/timezoneRUN sed -i s/#PermitRootLogin prohibit-password/PermitRootLogin yes/ /etc/ssh/sshd_config
RUN sed -i s/UsePAM yes/UsePAM no/ /etc/ssh/sshd_config
RUN echo root:123456 | chpasswdRUN echo alias llls -l ~/.bash_profile
RUN /bin/bash -c source ~/.bash_profile;CMD []代码摘自https://blog.csdn.net/m0_46825740/article/details/123550130
检查以下目录下面是否完成了以上两个文件 然后就是创建容器-t 是镜像的名字(tag)可以自己修改
docker build -t wzl .等待片刻之后就可以看到创建好的镜像了。
创建容器 最重要的是使用nvidia的GPU环境所以我们得配置运行环境修改daemon.json文件
sudo vim /etc/docker/daemon.json复制以下内容
{registry-mirrors: [https://f1z25q5p.mirror.aliyuncs.com],runtimes: {nvidia: {path: nvidia-container-runtime,runtimeArgs: []}}
}然后刷新并重启docker服务
sudo systemctl daemon-reload
sudo systemctl restart docker接下来就是根据镜像创建我们的容器了–name指定容器的名字–runtime指定运行环境-itd表示使用交互式且挂起py_11.3:latest是我们创建的镜像
sudo docker run --name wzl --runtimenvidia -itd py_11.3:latest /bin/bash进入镜像后输入nvidia-smi显示出GPU后我们就配置成功了 测试 activate base并查看conda版本
创建一个python文件比如叫test.py
import torch
print(torch.__version__)
print(torch.cuda.is_available())运行python test.py
至此大功告成(。・∀・)ノ 原创不易请勿转载本不富裕的访问量雪上加霜 博主首页https://wzlodq.blog.csdn.net/ 来都来了不评论两句吗 如果文章对你有帮助记得一键三连❤