我正在尝试在 docker 构建过程中嵌入测试构建,并在任一测试失败时中止它。我的 docker 文件如下所示:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["WebApplication1/WebApplication1.csproj", "WebApplication1/"]
COPY ["WebApplication1.Tests/WebApplication1.Tests.csproj", "WebApplication1.Tests/"]
RUN dotnet restore "WebApplication1/WebApplication1.csproj"
COPY . .
WORKDIR /src/WebApplication1
RUN dotnet build "WebApplication1.csproj" -c Release -o /app/build
FROM build AS test
WORKDIR /src/WebApplication1.Tests
RUN dotnet test --logger:trx
FROM build AS publish
WORKDIR /src/WebApplication1
RUN dotnet publish "WebApplication1.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApplication1.dll"]
有没有人知道如何处理它? 谢谢你
答案 0 :(得分:0)
Docker build 仅从您的 docker 文件生成 docker 镜像。它不运行它。
您需要在构建镜像后使用“docker run”才能将镜像作为容器实际启动(然后将执行您的入口点命令)
答案 1 :(得分:0)
您有一个多级 docker 文件,https://docs.docker.com/develop/develop-images/multistage-build/
对于您的情况,这将起作用
docker build --target test -t test-tag .
docker build -t webapp-image .
docker run -ti test-tag # will run tests and give you results
如果你想看到其他阶段的输出,你需要做同样的事情