基础镜像
WORKDIR="/data/docker/pytest_base_images"
mkdir -p ${WORKDIR}
cd ${WORKDIR}
cat >dockerfile<<'EOF'
# 使用官方的 CentOS 7 镜像作为基础镜像
FROM centos:7
# modify timezone
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# 更换 yum 源为阿里的源
RUN sed -i 's/#baseurl/baseurl/g' /etc/yum.repos.d/CentOS-Base.repo
RUN sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-Base.repo
RUN sed -i 's/http:\/\/mirror.centos.org/https:\/\/mirrors.aliyun.com/g' /etc/yum.repos.d/CentOS-Base.repo
# 安装 Java 8
RUN yum install -y java-1.8.0-openjdk
# 安装 Python 3
RUN yum install -y python3 python3-pip gcc python3-devel
## 安装拓展包
RUN yum install -y dos2unix
# 安装git
RUN yum install -y git
# 配置 Java 环境变量
ENV JAVA_HOME /usr/lib/jvm/jre-1.8.0-openjdk
ENV PATH $PATH:$JAVA_HOME/bin
ENV PYTHONIOENCODING=utf-8
ENV ALLURE_HOME /code/allure
ENV PATH $PATH:$ALLURE_HOME/bin
# 安装python依赖
RUN /usr/bin/pip3 install --upgrade pip -i https://mirrors.aliyun.com/pypi/simple
COPY ./requirements.txt /code/requirements.txt
RUN /usr/bin/pip3 install -r /code/requirements.txt -i https://mirrors.aliyun.com/pypi/simple
#
# 其他定制操作,比如拷贝应用代码等
EOF
cat >requirements.txt<<'EOF'
requests==2.26.0
certifi==2022.6.15
chardet==3.0.4
charset_normalizer==2.0.1
cryptography==3.4.7
idna==2.10
jsonpath==0.82
loguru==0.6.0
oss2==2.14.0
psutil==5.7.2
PyMySQL==1.0.2
pytest==6.2.4
simplejson==3.19.1
urllib3==1.26.6
PyYAML==6.0
allure_pytest==2.9.43
allure-python-commons==2.9.43
pytest-dependency==0.5.1
pytest-forked==1.3.0
pytest-html==2.1.1
pytest-metadata==1.11.0
pytest-ordering==0.6
pytest-parallel==0.1.0
pytest-rerunfailures==9.1.1
pytest-shell==0.2.3
pytest-testreport==1.1.5
pytest-xdist==3.0.2
python-dateutil==2.8.1
esdk-obs-python == 3.0.5
sqlparse==0.4.1
openpyxl==3.0.10
gitpython
tqdm
jinja2
schedule == 1.1.0
bs4 == 0.0.1
EOF
# 创建基础镜像
docker build -t pytest_base_images:1.0 .
work镜像
WORKDIR="/data/docker/data_compare"
mkdir -p ${WORKDIR}
cd ${WORKDIR}
cat >dockerfile<<'EOF'
# 使用提前制作好的pytest_base_image镜像作为基础镜像
FROM pytest_base_images:1.0
ADD . /code
WORKDIR /code
ENV PYTHONUNBUFFERED=1
CMD ["python3", "update_indicator_excel.py"]
EOF
标签:WORKDIR,mkdir,基础,cd,镜像,docker,data
From: https://www.cnblogs.com/chenzechao/p/18124320