2

In my solution I use a docker. When I try to build my image, every time I receive error:

Sending build context to Docker daemon 77.32MB

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 ["ProductCatalogApi.csproj", "src/Services/ProductCatalogApi/"]
 ---> 59d2cc3f4102
Step 7/16 : RUN dotnet restore "src/Services/ProductCatalogApi/ProductCatalogApi.csproj"
 ---> Running in 347a48e8ef6f
  Determining projects to restore...

     Retrying 'FindPackagesByIdAsync' for source 'https://api.nuget.org/v3-flatcontainer/system.resources.resourcemanager/index.json'.
      The SSL connection could not be established, see inner exception.
         Received an unexpected EOF or 0 bytes from the transport stream.
      Failed to download package 'System.IO.Compression.ZipFile.4.3.0' from 'https://api.nuget.org/v3-flatcontainer/system.io.compression.zipfile/4.3.0/system.io.compression.zipfile.4.3.0.nupkg'.
The command '/bin/sh -c dotnet restore "src/Services/ProductCatalogApi/ProductCatalogApi.csproj"' returned a non-zero code: 1

Dockerfile has a 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"]

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........

Serhii Chyzhyk
  • 108
  • 2
  • 13
  • Sergey, have you resolved this issue, if yes than please share how you can come out of this big issue? bex I am also facing the same one. – Saad Awan Jan 26 '21 at 10:11
  • for netcore 3.1.0 it is still a open issue. Here is the link to issue: https://github.com/NuGet/Home/issues/9020 – Ajeet Singh Mar 15 '21 at 07:18

3 Answers3

3

You can solve it by using the below line

RUN dotnet restore --disable-parallel

Also check here

malik masis
  • 487
  • 1
  • 6
  • 15
  • 3
    Worked for me. In addition, instead of disabling parallelism at all, setting 5 'maxHttpRequestsPerSource' in NuGet.config improve performances, and still should work. – Formalist Jun 08 '22 at 20:34
  • 1
    Worked for me too. I am on a super slow connection in remote part of Greece and this got it to pass. Thank you! – D3vtr0n Aug 08 '22 at 18:49
0

I had the same error, I tried this and it worked.

  • Stop all the running containers docker stop $(docker ps -aq)
  • Delete all the containers docker rm $(docker ps -aq) which are stopped by the previous commands.
  • Delete all the volumes by using docker volume rm $(docker volume ls -q)
  • Better to clean up all old docker images by using docker rmi -f $(docker images -a -q)
  • Or you could purge all the data by using Docker Desktop UI.
  • Then you could go to the src directory and build all the images again using docker-compose build and then followed by docker-compose up

!IMPORTANT Please note, the above commands will clean up all the docker related instances on that environment. So it's not recommended to run these on any production environment or any other environment where docker instances of any other applications are running.

resand91
  • 49
  • 1
  • 2
  • 7
-2

I replaced this

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base

on this

FROM microsoft/aspnetcore-build:2.0.0 AS build

and after that replaced this

FROM mcr.microsoft.com/dotnet/core/sdk:3.1

on this

FROM microsoft/aspnetcore:2.0.0

In my .csproj file replecad version of netcoreapp from 3.1 to 2.0. As I understood problems were in versions of docker images.

Serhii Chyzhyk
  • 108
  • 2
  • 13
  • but in this proposed solution, project will run in .netCore 2 framwork, but I want to run it in 3.1 version not in 2.0, – Saad Awan Jan 26 '21 at 08:21