简体   繁体   中英

how to include class library reference into docker file

i'm trying to build docker file for .net core application which is having reference of class library whenever i'm trying to build docker i'm getting below error.

Skipping project because it was not found

below is the docker file which i'm using

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "testapp.dll"]

You need to move the Dockerfile to the solution level, and reference the projects using [Folder]/[Project].csproj. Here is my Dockerfile (located in the solution level):

FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["SumApi/SumApi.csproj", "SumApi/"]
COPY ["Shared/Shared.csproj", "Shared/"]
RUN dotnet restore "SumApi/SumApi.csproj"
COPY . .
WORKDIR "/src/SumApi"
RUN dotnet build "SumApi.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "SumApi.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app`enter code here`
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "SumApi.dll"]

Learned it from here: https://imranarshad.com/dockerize.net-core-web-app-with-dependent-class-library/

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