When I use built-in DockerFile in Visual Studio, there are no errors, but when I try to create image and container using terminal, I get an error.

My built-in DockerFile

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER $APP_UID
WORKDIR /app
EXPOSE 5000
EXPOSE 5001

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["Services/Catalog/Course.Catalog.Service.Api/Course.Catalog.Service.Api.csproj", "Services/Catalog/Course.Catalog.Service.Api/"]
COPY ["Shared/Course.Shared/Course.Shared.csproj", "Shared/Course.Shared/"]
RUN dotnet restore "Services/Catalog/Course.Catalog.Service.Api/Course.Catalog.Service.Api.csproj"
COPY . .
WORKDIR "/src/Services/Catalog/Course.Catalog.Service.Api"
RUN dotnet build "Course.Catalog.Service.Api.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "Course.Catalog.Service.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Course.Catalog.Service.Api.dll"]

The error when I try to run in terminal

docker build -t catalog-service .
[+] Building 1.0s (12/18)
docker:default

=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 1.02kB 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for mcr.microsoft.com/dotnet/sdk:8.0 0.0s
=> [internal] load metadata for mcr.microsoft.com/dotnet/aspnet:8.0 0.0s
=> [build 1/8] FROM mcr.microsoft.com/dotnet/sdk:8.0 0.1s
=> [internal] load build context 0.9s
=> => transferring context: 38.57MB 0.9s
=> [base 1/2] FROM mcr.microsoft.com/dotnet/aspnet:8.0 0.1s
=> [base 2/2] WORKDIR /app 0.1s
=> [build 2/8] WORKDIR /src 0.1s
=> [final 1/2] WORKDIR /app 0.0s

=> ERROR [build 3/8] COPY [Services/Catalog/Course.Catalog.Service.Api/Course.Catalog.Service.Api.csproj, Services/Catalog/Course.Catalog.Service.Api/] 0.0s => ERROR [build 4/8] COPY [Shared/Course.Shared/Course.Shared.csproj, Shared/Course.Shared/] 0.0s

[build 3/8] COPY [Services/Catalog/Course.Catalog.Service.Api/Course.Catalog.Service.Api.csproj, Services/Catalog/Course.Catalog.Service.Api/]:

[build 4/8] COPY [Shared/Course.Shared/Course.Shared.csproj, Shared/Course.Shared/]:

Dockerfile:11

9 | WORKDIR /src
10 | COPY ["Services/Catalog/Course.Catalog.Service.Api/Course.Catalog.Service.Api.csproj", "Services/Catalog/Course.Catalog.Service.Api/"]
11 | >>> COPY ["Shared/Course.Shared/Course.Shared.csproj", "Shared/Course.Shared/"]
12 | RUN dotnet restore "Services/Catalog/Course.Catalog.Service.Api/Course.Catalog.Service.Api.csproj"
13 | COPY . .

ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref bbe3e021-99e0-463c-b63f-1efe01732795::mokfn9f579f2n470tpes9iryv: "/Shared/Course.Shared/Course.Shared.csproj": not found

I was expecting it to run in terminal using docker commands. Not only in Visual Studio.

0

There are 0 best solutions below