0

我正在尝试使用新的 docker 工具包来构建图像,因为我们需要 2 组不同的变量,我的 docker 文件如下所示:

FROM python:3.7 as base
RUN apt-get update -y

FROM base as basic_build
WORKDIR /app
COPY ./path/to/requirements.txt requirements.txt
RUN pip install -r requirements.txt
ENV DEPLOY_TYPE=local
RUN ls -lrth

FROM basic_build as testing_build
# for testing
ENV A_VARIBLE_TEST=some_string
COPY ./some/files/ /app/
EXPOSE 5000
CMD ["python", "-m", "flask", "run"]


FROM basic_build as normal_build
ENV my_docker_test_var=see_if_prints_in_log
EXPOSE 5000
CMD ["python", "-m", "flask", "run"]

在詹金斯被称为:

sh "DOCKER_BUILDKIT=1 docker build --file ${docker_file_path} --target testing_build --no-cache ${WORKSPACE}"

但日志没有显示设置 ENV 的行

我们可以看到运行 pip 安装、COPY 但不是 ENV:

#28 [basic_build 22/24] RUN ls -lrth
#28 sha256
#28 0.351 total 20K
#28 0.351 -rw-r--r--. 1 root root 5.0K Jul 14 16:04 file1.py
#28 0.351 -rw-r--r--. 1 root root   30 Jul 14 16:04 file2.py
...
#28 DONE 0.4s

#29 [basic_build 23/24] RUN mkdir /app/temp
#29 sha256:e1edb01f6c54b011bed2a1695a982985f6a418668509602436e17c0528dc17ba
#29 DONE 0.4s

#31 [testing_build 1/5] COPY ./some/path/ /app/
# sha256

但不是当我设置 ENV 时...

--progress=plain

这样的:

sh "DOCKER_BUILDKIT=1 docker build --file ${docker_file_path} --target testing_build --no-cache ${WORKSPACE} --progress=plain"

我错过了什么?还是 ENV 不再显示?还是没有设置?期望在一行中看到如下内容:

Step 28/75 : DEPLOY_TYPE=local
 ---> Running in #####28a62
4

0 回答 0