Reputation: 122
My VS 2019 genereted Dockerfile with the next code:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /src
COPY ["src/Services/ProductCatalogApi/ProductCatalogApi.csproj", "src/Services/ProductCatalogApi/"]
RUN dotnet restore "src/Services/ProductCatalogApi/ProductCatalogApi.csproj"
COPY . .
WORKDIR "/src/Services/ProductCatalogApi"
RUN dotnet build "ProductCatalogApi.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "ProductCatalogApi.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ProductCatalogApi.dll"]
And when I run my Dockerfile with command
docker build .
i receved next:
Sending build context to Docker daemon 77.49MB
Step 1/16 : FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
---> 014a41b1f39a
Step 2/16 : WORKDIR /app
---> Using cache
---> c3eb79db5e63
Step 3/16 : EXPOSE 80
---> Using cache
---> f23ddd06f8f8
Step 4/16 : FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
---> 006ded9ddf29
Step 5/16 : WORKDIR /src
---> Using cache
---> d8016eaadf87
Step 6/16 : COPY ["src/Services/ProductCatalogApi/ProductCatalogApi.csproj", "src/Services/ProductCatalogApi/"]
COPY failed: stat /var/lib/docker/tmp/docker-builder040062339/src/Services/ProductCatalogApi/ProductCatalogApi.csproj: no such file or directory
My .csproj file:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>ShoesOnContainers.Services.ProductCatalogApi</RootNamespace>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>..\..\..</DockerfileContext>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.5" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.9.10" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.9.10" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.5.1" />
</ItemGroup>
</Project>
During all my day I am trying to build my image by other way and every time I receive errors. Help somebody, please........
Upvotes: 0
Views: 65
Reputation: 51
src/Services/ProductCatalogApi/ProductCatalogApi.csproj
does not exists from the folder you are running it from.
If the dockerfile is in the same folder as csproj, then it should be
COPY ["ProductCatalogApi.csproj", "src/Services/ProductCatalogApi/"]
It's a bit tricky then, if you are using docker-compose, the path has to be relative path to the docker-compose file you are trying to run
Upvotes: 1