【发布时间】:2023-04-07 05:58:01
【问题描述】:
我有以下 docker 文件,它有多个构建目标,包括 .net 单元测试。
由于某种原因,它在构建期间没有通过单元测试,但如果我评论 testrunner 并测试构建目标点,它就可以工作。
有什么想法吗?
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/core/runtime:3.1 AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /src
COPY *.sln .
COPY ["Pokemon.API/*.csproj", "./Pokemon.API/"]
COPY ["Pokemon.Core/*.csproj", "./Pokemon.Core/"]
COPY ["Pokemon.Models/*.csproj", "./Pokemon.Models/"]
COPY ["Pokemon.Test/*.csproj", "./Pokemon.Test/"]
RUN dotnet restore
# copy full solution over
COPY . .
RUN dotnet build
# create a new build target called testrunner
FROM build AS testrunner
WORKDIR /src/Pokemon.Test
CMD ["dotnet", "test", "--logger:trx"]
# run the unit tests
FROM build AS test
WORKDIR /src/Pokemon.Test
RUN dotnet test --logger:trx
FROM build AS release
WORKDIR "/src/Pokemon.API"
RUN dotnet build "Pokemon.API.csproj" -c Release -o /app/build
FROM build AS publish
WORKDIR "/src/Pokemon.API"
RUN dotnet publish "Pokemon.API.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Pokemon.API.dll"]
如果我在 Docker 文件的下面一行注释,它会在构建期间成功运行单元测试
# create a new build target called testrunner
#FROM build AS testrunner
#WORKDIR /src/Pokemon.Test
#CMD ["dotnet", "test", "--logger:trx"]
# run the unit tests
#FROM build AS test
#WORKDIR /src/Pokemon.Test
RUN dotnet test --logger:trx
【问题讨论】:
标签: .net docker dockerfile containers .net-core-3.1