简体   繁体   中英

Problems with Docker multiple projects in solution .NET

This is the strucure of my folder

ROOT FOLDER
    |--- Login.sln
    |--- Login.Api
        -- Login.WebApi.csproj
    |-- Domain
         -- Domain.csproj
    |-- BusinessLogic
        |-- BusinessLogic.csproj
    |---DataAccess
        |-- DataAccess.csproj
|-- BusinessLogic.csproj
    |---Dockerfile

And this is my current dockerfile

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY . .

RUN dotnet restore "/Login/Login.WebApi.csproj"
WORKDIR "/src/."
COPY . .
RUN dotnet build "Login.WebApi.csproj" -c Release -o /app/build

FROM build as publish
RUN dotnet publish "Login.WebApi.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENV ASPNETCORE_URLS http://*:PORT_NUMBER
ENTRYPOINT ["dotnet", "Login.WebApi.dll"]

Right now is not working because it can't do the restore. I do not know if this is the correct way to do it

You don't need to do a restore; dotnet build will do that anyway. Also I'd recommened you build the solution instead of individual projects. And finally you don't need the double quotes. Try this:

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY . .

RUN dotnet build Login.sln -c Release -o /app/build

FROM build as publish
RUN dotnet publish Login.Api/Login.Api.csproj -c Release -o /app/publish

The rest of the dockerfile is ok I think.

Also double check the names of the directories, they don't match your folder structure.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM