Building a Docker image from a multi project dot net core solution

前端 未结 1 2026
暗喜
暗喜 2020-12-31 13:09

I am trying to build a docker image from a visual studio solution that consists of two projects:

  • one project contains common code (http methods, logging etc)
相关标签:
1条回答
  • 2020-12-31 13:43

    If you use "standard" Dockerfile template from Visual Studio, you might have issue with having your "common" project being built on your local PC (probably windows) and the "main" project being built in docker container (probably Linux). the "main" dll is referencing windows-built dll, hence the issues.

    Make sure you are copying not only main project, but also the common project, so dotnet can build it in docker also.

    Try out this dockerfile:

    FROM microsoft/aspnetcore:2.0 AS base
    WORKDIR /app
    ENV ASPNETCORE_ENVIRONMENT=Production
    ENV ASPNETCORE_URLS http://*:5000
    EXPOSE 5000
    
    FROM microsoft/aspnetcore-build:2.0 AS builder
    ARG Configuration=Release
    WORKDIR /src
    COPY *.sln ./
    COPY Project.Main/Project.Main.csproj Project.Main/
    COPY Project.Common/Project.Common.csproj Project.Common/
    RUN dotnet restore
    COPY . .
    WORKDIR /src/ProjectMain
    RUN dotnet build -c $Configuration -o /app
    
    FROM builder AS publish
    ARG Configuration=Release
    RUN dotnet publish -c $Configuration -o /app
    
    FROM base AS final
    WORKDIR /app
    COPY --from=publish /app .
    ENTRYPOINT ["dotnet", "Project.Main.dll"]
    

    Although is to build the "Main" project, it's executed on the sln level.

    0 讨论(0)
提交回复
热议问题