`In other words, what should the dockerfile file be like in a project with an API layer and UI layer in an N-layer architecture?

FROM mcr.microsoft.com/dotnet/sdk:7.0 as build
WORKDIR /app


COPY ./SignalR.EntityLayer/*.csproj ./SignalR.EntityLayer/
COPY ./SignalR.DataAccessLayer/*.csproj ./SignalR.DataAccessLayer/
COPY ./SignalR.BussinessLayer/*.csproj ./SignalR.BussinessLayer/
COPY ./SignalR.DtoLayer/*.csproj ./SignalR.DtoLayer/
COPY ./SignalR.Api/*.csproj ./SignalR.Api/
COPY *.sln .
RUN dotnet restore


COPY . .
RUN dotnet publish ./SignalR.Api/*.csproj -o /publish/


FROM mcr.microsoft.com/dotnet/runtime:7.0
WORKDIR /app


COPY --from=build /usr/share/dotnet /usr/share/dotnet


COPY --from=build /publish .


ENV ASPNETCORE_URLS="http://*:5000"


ENTRYPOINT ["dotnet", "SignalR.Api.dll"]

I created such a dockerfile in Solution. But when creating the image => => ERROR [build 9/11] RUN dotnet restore 1.7s

[build 9/11] RUN dotnet restore: 0.962 /usr/share/dotnet/sdk/7.0.404/NuGet.targets(400,5): error MSB3202: The project file "/app/SignalR.WebUI/SignalR.WebUI.csproj" was not found. [/app/SignalRProject.sln]

I get an error. Even though I included the WebUI layer. In other words, what should the dockerfile file be like in a project with an API layer and UI layer in an N-layer architecture? `

1

There are 1 best solutions below

0
Nathan Carlson - MSFT On

I recommend using the tooling in VS or VS Code to generate a Dockerfile for you:
Adding a Dockerfile in VS Code
Adding a Dockerfile in VS
They will handle creating Dockerfiles that can handle your project references.
Note: You will need different Dockerfiles for your API layer and UI layer.

Bonus tip: You can use the Compose support in both tools to orchestrate starting your services VS Code docs / VS docs

P.S. The two problems I can spot in your Dockerfile:

  1. You're not copying ./SignalR.WebUI/SignalR.WebUI.csproj before calling restore
  2. You only need to call restore on ./SignalR.Api/*.csproj, you're not building other projects, no need to restore (may side-step the issue 1 and the error you're seeing)
  3. COPY --from=build /usr/share/dotnet /usr/share/dotnet should not be needed and is adding bloat to your final image.