ASP.NET Core build docker image having shared libraries

Viewed 1301

I'm working in a microservice environemnt where there are shared libraries between these microservices.

These libraries are stored in a different location on the disk, a "shared" location, and are directly referenced by these microservices.

In a .csproj of such a microservice you would see something like this.

<ItemGroup>
   <ProjectReference Include="..\..\..\Shared1.csproj" />
<ItemGropu>

Now in each of these microservices I have a dockerfile

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY . .
COPY ../../../Users/boris/Desktop/shared/Shared/Shared/Shared.csproj .
RUN dotnet restore "WebUi.csproj"

WORKDIR /src/.
RUN dotnet build "WebUi.csproj" -c Release -o /app/build

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

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
RUN ls
ENTRYPOINT ["dotnet", "WebUi.dll"]

when building a image

docker build -f dockerfile .

I'm getting

ERROR [build 4/7] COPY ..\..\..\Users\boris\Desktop\shared\Shared\Shared\Shared.csproj .

[build 4/7] COPY ......\Users\boris\Desktop\shared\Shared\Shared\Shared.csproj .: failed to solve with frontend dockerfile.v0: failed to build LLB: failed to compute cache key: "/..\..\..\Users\boris\Desktop\shared\Shared\Shared\Shared.csproj" not found: not found PS C:.demos\hangfire-dashboard\WebUi> docker build -f .\dockerfile -t web . [+] Building 0.2s (10/18)

I'm thinking it's because of the build context, but not sure.

Any ideas on how can I fix this ?

1 Answers

Ok first thing first rename the dockerfile to Dockerfile. Next up is the path correct in the first place? I assume your csproj exists in the same folder as your Dockerfile and in your csproj you use <ProjectReference Include="..\..\..\Shared1.csproj" /> whereas in the docker file you use ../../../Users/boris/Desktop/shared/Shared/Shared/Shared.csproj so if the csproj AND the Dockerfile exist in the same directory the path is simply incorrect.

Related