我有以下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 命令的多种不同变体和组合,但到目前为止我还缺少正确的组合
每个
FROM
阶段都会重置所有构建参数。
在
ARG API_GATEWAY_STAGE_NAME
阶段需要FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build