Dockerfile 多阶段构建参数传递

Dockerfile 多阶段构建参数传递

dockerfile

ARG SVC1
ARG SVC2

##### BUILD STAGE
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS BUILD
ARG SVC1

WORKDIR /workspace

RUN mkdir ${SVC1}

##### RUN STAGE
FROM mcr.microsoft.com/dotnet/aspnet:3.1
ARG SVC2
ENV SVC2=${SVC2}

COPY --from=BUILD /workspace /workspace

WORKDIR /workspace

RUN mkdir ${SVC2}
  • ARG 声明传入的参数
  • FROM 分隔了不同的构建阶段
  • 不同构建阶段必须先声明 ARG 后才能使用
ARG SVC
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS BUILD
ARG SVC
...
FROM mcr.microsoft.com/dotnet/aspnet:3.1
ARG SVC
...
  • COPY --from=BUILD 从 BUILD 阶段拷贝

docker build 构建镜像

docker build -t test --build-arg SVC1="text1" --build-arg SVC2="text2" .

通过 --build-arg KEY="VAL"

你可能感兴趣的:(docker)