Dockerfile - sed 命令不替换 ARG 变量

问题描述 投票:0回答:1

我有以下dockerfile

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /WebAdmin
EXPOSE 80
EXPOSE 443
ARG API_GATEWAY_STAGE_NAME
RUN echo "API_GATEWAY_STAGE_NAME is $API_GATEWAY_STAGE_NAME" 

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["MyApp.Web.Admin/MyApp.Web.Admin.csproj", "MyApp.Web.Admin/"]
RUN dotnet restore "./MyApp.Web.Admin/./MyApp.Web.Admin.csproj"
COPY . .
WORKDIR "/src/MyApp.Web.Admin"
RUN sed -i "s/~\//\/${API_GATEWAY_STAGE_NAME}\//g" ./Views/Shared/_Layout.cshtml
RUN more ./Views/Shared/_Layout.cshtml
RUN dotnet build "./MyApp.Web.Admin.csproj" -c $BUILD_CONFIGURATION -o /WebAdmin/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./MyApp.Web.Admin.csproj" -c $BUILD_CONFIGURATION -o /WebAdmin/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /WebAdmin
COPY --from=publish /WebAdmin/publish .
ENTRYPOINT ["dotnet", "MyApp.Web.Admin.dll"]

用 ARG API_GATEWAY_STAGE_NAME 替换所有出现的 ~ 的 sed 命令不起作用。该变量永远不会扩展,我们只是在 API_GATEWAY_STAGE_NAME 应该是的位置留下一个空白

我已经尝试了 sed 命令的多种不同变体和组合,但到目前为止我还缺少正确的组合

unix sed dockerfile
1个回答
0
投票

每个

FROM
阶段都会重置所有构建参数。

ARG API_GATEWAY_STAGE_NAME
阶段需要
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build

© www.soinside.com 2019 - 2024. All rights reserved.