如何在 dockerfile 中获取 teamcity 环境参数?

How get teamcity env params in dockerfile?

我在 teamcity 中有几个构建步骤,用于构建和推送 docker 图像。如何从 dockerfile 中的 teamcity 获取环境参数。现在 dockerfile 看起来像:

FROM python:3.8.9-slim-buster
ENV test24=2626
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

EXPOSE 8000
CMD [ "sh", "./app.sh" ]

您可以将 --build-arg ARG_NAME=ARG_VALUE 选项传递给 docker build 命令,然后在 Dockerfile 中定义一个 ARG 来获取值。例如:

ARG ARG_VALUE=DEFAULT_ARG_VALUE_IF_NOT_SPECIFIED

LABEL com.Whosebug.arg="${ARG_VALUE}"