构建Docker基础镜像(ubuntu20.04+python3.9.10+pytorch

编程入门 行业动态 更新时间:2024-10-19 21:24:52

构建Docker基础<a href=https://www.elefans.com/category/jswz/34/1770431.html style=镜像(ubuntu20.04+python3.9.10+pytorch"/>

构建Docker基础镜像(ubuntu20.04+python3.9.10+pytorch

文章目录

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


一、前置条件

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

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

内容如下

deb / focal main restricted universe multiverse
deb-src / focal main restricted universe multiversedeb / focal-security main restricted universe multiverse
deb-src / focal-security main restricted universe multiversedeb / focal-updates main restricted universe multiverse
deb-src / focal-updates main restricted universe multiversedeb / focal-proposed main restricted universe multiverse
deb-src / focal-proposed main restricted universe multiversedeb / focal-backports main restricted universe multiverse
deb-src / focal-backports main restricted universe multiverse

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

访问官网下载页 /
下拉选择 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/timezoneRUN 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 --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 /
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  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 文件打包

更多推荐

构建Docker基础镜像(ubuntu20.04+python3.9.10+pytorch

本文发布于:2023-11-14 14:30:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1587783.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:镜像   基础   Docker   pytorch

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!