Dockerfile构建python 运行项目运行环境
https://blog.csdn.net/qq_24487005/article/details/123380810
目錄
構(gòu)建思路
DockerFile腳本
環(huán)境文件解析
pip.conf
sources.list
openssl.cnf
localtime
install.sh
startup.sh
docker鏡像構(gòu)建
構(gòu)建思路
1、把容器內(nèi)需要用到的文件全部復(fù)制到容器中
2、設(shè)置一個(gè)工作目錄,把項(xiàng)目代碼共享到工作目錄中運(yùn)行
3、把需要執(zhí)行的shell命令寫在一個(gè).sh文件中,統(tǒng)一執(zhí)行。因?yàn)镈ockerfile 的指令每執(zhí)行一次都會(huì)在 docker 上新建一層。所以過(guò)多無(wú)意義的層,會(huì)造成鏡像膨脹過(guò)大;RUN 是在 docker build執(zhí)行腳本
4、配置容器啟動(dòng)自動(dòng)執(zhí)行腳本,CMD 在docker run 時(shí)運(yùn)行運(yùn)行腳本
DockerFile腳本 # 基于鏡像基礎(chǔ) FROM python:3.9.5# 復(fù)制文件到容器中 ADD ./docker/pip.conf /root/.pip/pip.conf ADD ./docker/sources.list /etc/apt/sources.list ADD ./docker/openssl.cnf /etc/ssl/openssl.cnf ADD ./docker/localtime /etc/localtime ADD ./docker/requirements.txt /var/requirements.txt ADD ./docker/startup.sh /var/startup.sh ADD ./docker/install.sh /var/install.sh# 工作目錄 /var/app WORKDIR /var/appRUN /var/install.shCMD /var/startup.sh環(huán)境文件解析
pip.conf
配置pip國(guó)內(nèi)源,容器內(nèi)文件路徑:/root/.pip/pip.conf
配置容器環(huán)境包下載的國(guó)內(nèi)源,容器內(nèi)文件路徑:/etc/apt/sources.list
deb http://mirrors.aliyun.com/debian/ buster main non-free contrib deb http://mirrors.aliyun.com/debian-security buster/updates main deb http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib deb http://mirrors.aliyun.com/debian/ buster-backports main non-free contribdeb-src http://mirrors.aliyun.com/debian-security buster/updates main deb-src http://mirrors.aliyun.com/debian/ buster main non-free contrib deb-src http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib deb-src http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib openssl.cnf處理ssl.SSLError: [SSL: DH_KEY_TOO_SMALL] dh key too small問(wèn)題
容器內(nèi)文件路徑:/etc/ssl/openssl.cnf
修改文件參數(shù)即可
[system_default_sect] MinProtocol = TLSv1.2 #CipherString = DEFAULT@SECLEVEL=2 CipherString = DEFAULT@SECLEVEL=1 localtime同步系統(tǒng)時(shí)間到容器內(nèi),容器內(nèi)文件路徑:/etc/localtime
install.sh
構(gòu)建容器時(shí)需要執(zhí)行的shell命令
startup.sh
容器啟動(dòng)時(shí)自動(dòng)執(zhí)行的腳本命令,一般是直接啟動(dòng)項(xiàng)目
docker鏡像構(gòu)建
準(zhǔn)備好以上文件之后,在Dockerfile文件目錄下執(zhí)行一下命令構(gòu)建鏡像:
總結(jié)
以上是生活随笔為你收集整理的Dockerfile构建python 运行项目运行环境的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 基于TextRank算法的文本摘要(附P
- 下一篇: pkuseg-python的postag