【发布时间】:2023-03-07 05:41:01
【问题描述】:
我目前正在为 .net Core 3.1 构建 Docker,其中缓存了 RUN 步骤,它们不应该这样做,因为应该始终执行:
#10 [build 4/4] RUN dotnet publish "WKIS Solution.sln" -c UserManagementFrontendRelease -p:version=1.2.4 -o /app/publish --configfile FrontendWebApplication.UserManagement.Cicd/nuget.config
#10 sha256:e8aeefc43305f5ab93d8c8fb78658174bdaa14d42c560daf9d764848da7f251c
#10 CACHED
以下步骤最有可能失败的原因是:ERROR: "/app/publish" not found: not found:
#14 [final 2/2] COPY --from=base /app/publish .
#14 sha256:4a30ee4113a62bfd40731cdb0cd3a498eaee357df5736019ebd0629bd07f178e
#14 ERROR: "/app/publish" not found: not found
我将 Windows 上的 Docker Desktop 更新到 20.10.11 版本,build dea9396,结果的输出看起来略有不同,但结果相同:
=> CACHED [base 2/2] WORKDIR /app 0.0s
=> CACHED [build 2/4] WORKDIR /src 0.0s
=> CACHED [build 3/4] COPY . . 0.0s
=> CACHED [build 4/4] RUN dotnet publish "WKIS Solution.sln" -c UserManagementFrontendRelease -p:version=1.2.4 - 0.0s
docker 文件很简单:
FROM registry.intranet.company/ubi8/dotnet-31-runtime AS base
WORKDIR /app
EXPOSE 80
FROM registry.intranet.company/ubi8/dotnet-31 AS build
WORKDIR /src
USER root
COPY . .
RUN dotnet publish "WKIS Solution.sln" -c UserManagementFrontendRelease -p:version=1.2.4 -o /app/publish --configfile FrontendWebApplication.UserManagement.Cicd/nuget.config
USER default
FROM build AS final
WORKDIR /app
COPY --from=base /app/publish .
ENTRYPOINT ["dotnet", "FrontendWebApplication.UserManagement.dll"]
我已经尝试了以下方法来解决这个问题:
- 在 docker 中修剪所有内容
- 停止和启动 Docker 桌面
- 致电
docker build --no-cache - 在 Dockerfile 内的
RUN语句中添加 --no-cache 选项,如下所示:RUN dotnet publish "WKIS Solution.sln" -c UserManagementFrontendRelease -p:version=1.2.4 -o /app/publish --configfile FrontendWebApplication.UserManagement.Cicd/nuget.config --no-cache
我不能 100% 确定缓存是否对找不到的文件夹负责,所以原因可能完全不同,但由于我找不到禁用缓存的方法,我只是简单地不知道,这是我最好的猜测。
【问题讨论】:
-
在
base阶段,您正在创建一个空的/app目录,但从未在其中执行任何操作。你需要COPY --from=build /src/???吗?
标签: docker .net-core dockerfile