赞
踩
docker search centos
docker pull centos # 默认latest
# 这边用的python3.11,需要提前下好
wget https://www.python.org/ftp/python/3.11.2/Python-3.11.2.tgz
# 1.下载阿里源
wget https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist
个人就觉得写一个的docker 会方便后期更新,比如在git更新代码,可以直接重新打包,不需要再写其他的东西
# 设置基础镜像,我是把centos:latest重新打标签给打成了centos:8 # docker tag centos:latest centos:8 FROM centos:8 # 执行用户设置为root USER root # 拷贝阿里源文件至镜像内部 COPY ./Centos-vault-8.5.2111.repo /home # 拷贝python3.11包至镜像内部 COPY ./Python-3.11.2.tgz /home # 拷贝python所需要安装的依赖包文件 COPY ./requirements.txt /home # 拷贝python文件至镜像内部 COPY ./app.py /home # 将运行目录调整为/home WORKDIR /home # 我这里是直接删除镜像内部原有的源3 RUN rm -rf /etc/yum.repos.d/* # 将阿里源拷贝至镜像源内部 RUN cp -r ./Centos-vault-8.5.2111.repo /etc/yum.repos.d/CentOS-Base.repo # 更新一下YUM cache RUN yum clean all RUN yum makecache # 安装一下python所需依赖包 RUN yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel libffi-devel xz-devel RUN yum install -y gcc RUN yum install -y make #解压python,并安装python RUN tar -zxvf Python-3.11.2.tgz -C /usr/local/ WORKDIR /usr/local/Python-3.11.2 RUN ./configure --prefix=/usr/local/python3 RUN make && make install # 将python添加到系统路径中 ENV PATH="/usr/local/python3/bin:${PATH}" # 在安装python的时候更换了工作目录,现在更换回来 WORKDIR /home RUN pip3 install -r requirements.txt CMD ["python3", "app.py"]
我直接写了一个shell脚本,方便下次更新使用,也方便和git
进行配合
#!/bin/bash function build_image() { docker_name="*****/******/${image_name}:${MODE}_${TIMENOW}" docker build -t ${docker_name} . docker push ${docker_name} # 如果自己本地测试,可以删除这一行 #check_ret $? $FUNCNAME } function check_ret() { if [ $1 != 0 ]; then echo "$2 Failure, Exit!" exit $1 fi } image_name='python' MODE="date" TIMENOW=$(date +%y.%m.%d.%H%M) echo "build workflow start .." build_image echo "build workflow end .."
`
友情提示:如果有问题可以随时在评论区评论
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。