当前位置: 首页 > news >正文

构建Docker基础镜像(ubuntu20.04+python3.9.10+pytorch-gpu-cuda11.8)

文章目录

  • 一、前置条件
    • 1.创建 ubuntu 镜像源文件【sources.list】
    • 2.下载 python 安装包【Python-3.9.10.tgz】
  • 二、构建方法
    • 1.构建目录
    • 2.创建DockerFile
    • 3.打包镜像


一、前置条件

  1. 配置一下 ubuntu 的镜像源
  2. 下载 python 安装包

1.创建 ubuntu 镜像源文件【sources.list】

内容如下

deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

2.下载 python 安装包【Python-3.9.10.tgz】

访问官网下载页 https://www.python.org/downloads/release/python-3910/
下拉选择 Gzipped 包
在这里插入图片描述


二、构建方法

1.构建目录

|---baseIMG_ub2004py3910pytorchgpucuda118||-----python|		|-----Python-3.9.10.tgz||-----ubuntu|		|-----sources.list||-----Dockerfile

2.创建DockerFile

#FROM python:3.9
FROM ubuntu:20.04# 作者
MAINTAINER ps# 工作目录
WORKDIR /baseIMG_ub2004py3910pytorchgpucuda118# 宿主机文件复制到镜像
ADD . /baseIMG_ub2004py3910pytorchgpucuda118# 配置时区
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone# RUN rm -f /etc/localtime
# RUN  ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' > /etc/timezone# 更新ubuntu
RUN mv ./ubuntu/sources.list /etc/apt/sources.list
#RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 871920D1991BC93C
RUN apt --fix-broken -y install
RUN apt -y update
RUN apt -y upgrade## 安装python
#RUN apt-get install python3.7# # 安装chrome
# ## 安装依赖
# RUN apt -y install libxss1 libappindicator1 libindicator7 fonts-liberation libasound2
# RUN apt -y install libatk-bridge2.0-0 libatspi2.0-0 libcurl3-gnutls libcurl3-nss libcurl4
# RUN apt -y install libdrm2 libgbm1 libgtk-3-0 libxkbcommon0 xdg-utils wget
# RUN apt --fix-broken -y install
# # 安装浏览器
# RUN dpkg -i ./chrome/google-chrome-stable_current_amd64.deb
# # 查看版本
# RUN google-chrome --version
# # Google Chrome 101.0.4951.64
# 
# # 安装chromedriver
# # 安装unzip
# RUN apt install unzip
# # 解压
# RUN unzip ./chrome/chromedriver_linux64.zip
# # 移动并创建软连接到默认路径,后续启动selenium时就不需要指定chromedriver的路径了
# RUN mv ./chromedriver /usr/local/share/chromedriver
# RUN ln -s /usr/local/share/chromedriver /usr/bin/chromedriver# 安装python
RUN apt -y install build-essential libbz2-dev
RUN apt -y install libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev
RUN apt -y install zlib1g-dev
RUN mv ./python /usr/local/bin/python
RUN cd /usr/local/bin/python && tar -xzvf Python-3.9.10.tgz && cd Python-3.9.10 && ./configure --enable-optimizations && make && make install# 安装pytorch-gpu-cuda11.8
RUN apt install -y libbz2-dev
# 阿里源
RUN pip3 config set global.index-url https://mirrors.aliyun.com/pypi/simple/
RUN python3 -m pip install -U pip setuptools wheel
RUN pip3 install apscheduler## CPU
#RUN pip3 install torch torchvision torchaudio
# GPU
RUN pip3 install --timeout 18000 torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118# linux下需要此步骤以防报错  ModuleNotFoundError: No module named '_bz2'
# RUN cp /usr/lib/python3.8/lib-dynload/_bz2.cpython-38-x86_64-linux-gnu.so /usr/local/lib/python3.7/lib-dynload/_bz2.cpython-37m-x86_64-linux-gnu.so# 镜像打包命令
# docker build -t ub2004py371chm101chmdr101:latest .

3.打包镜像

docker build -t ub2004py3910pytorchgpucuda118:latest .

ps:创建镜像名为 ub2004py3910pytorchgpucuda118 标签为 latest 的镜像,从当前路径下的 DockerFile 文件打包

http://www.lryc.cn/news/230569.html

相关文章:

  • Flowable自定义Id生成器
  • 怎样正确选择等保测评机构开展等保测评工作?
  • 【论文阅读笔记】Detecting AI Trojans Using Meta Neural Analysis
  • 【PyTorch教程】如何使用PyTorch分布式并行模块DistributedDataParallel(DDP)进行多卡训练
  • Istio学习笔记-体验istio
  • fastjson 系列漏洞
  • odoo前端js对象的扩展方法
  • 力扣双周赛 -- 117(容斥原理专场)
  • 基于Rabbitmq和Redis的延迟消息实现
  • Masked Relation Learning for DeepFake Detection
  • R语言爬虫程序自动爬取图片并下载
  • 2023年10月国产数据库大事记-墨天轮
  • Linux内核分析(十四)--内存管理之malloc、free 实现原理
  • Hive函数
  • 教资笔记(目录)
  • np.repeat()的注意事项
  • 239. 滑动窗口最大值
  • c++ barrier 使用详解
  • c# 接口
  • 1、NPC 三电平SVPWM simulink仿真
  • JAVA对象列表强转失败,更好的方法
  • 2023最新版本 从零基础入门C++与QT(学习笔记) -5- 动态内存分配(new)
  • asp.net校园招聘管理系统VS开发sqlserver数据库web结构c#编程Microsoft Visual Studio
  • flink的键值分区状态自动过期ttl配置
  • 解决Mac配置maven环境后,关闭终端后环境失效的问题(适用于所有终端关闭后环境失效的问题)
  • springboot运行jar包,实现复制jar包resources下文件、文件夹(可支持包含子文件夹)到指定的目录
  • Webpack Bundle Analyzer包分析器
  • SQL-----STUDENT
  • OpenCV入门——图像视频的加载与展示一些API
  • Control的Invoke和BeginInvoke