5
votes

I have an asp.net core docker image. The last time I tried building it was 2 months ago. Now, I'm getting an error building.

Any ideas? Something broke on the Microsoft docker image? This is also breaking when trying to publish and run on an Elasticbeanstalk instance.

Complete Error Log

/usr/share/dotnet/sdk/3.1.201/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(234,5): error NETSDK1064: Package DnsClient, version 1.2.0 was not found. It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions. [/app/BacktraderDataApi.csproj] The command '/bin/sh -c dotnet publish -c Release -o out' returned a non-zero code: 1

dockerfile

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

COPY *.csproj ./
RUN dotnet restore

COPY . ./
RUN dotnet publish -c Release -o out

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /app
COPY --from=build-env /app/out .
EXPOSE 5000
ENTRYPOINT ["dotnet", "myApp.dll"]
5

5 Answers

7
votes

When solutions like using --no-cache are not restoring at all work, it usually indicates that artifact from the host machine are getting copied into the build container. This can cause problems when the host machine and build container have different RIDs. This can commonly occur on Windows machines when running linux containers. The .NET Core Docker Samples suggest using a .dockerignore file to avoid coping the bin and obj directories with your Dockerfiles.

4
votes

For me it helped adding a --no-cache flag

RUN dotnet publish -c Release -o out --no-cache
2
votes

Based on the information posted at https://github.com/microsoft/containerregistry/issues/20 for this same issue as well as the information here I tried the following:

  1. dotnet new web
  2. Edit the csproj and added the following:
  <ItemGroup>
    <PackageReference Include="MongoDB.Driver" Version="2.10.1" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
  </ItemGroup>
  1. Created the following Dockerfile
# https://hub.docker.com/_/microsoft-dotnet-core
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /source

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

# copy and publish app and libraries
COPY . .
RUN dotnet publish -c release -o /app --no-restore


# final stage/image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /app
COPY --from=build /app ./
ENTRYPOINT ["dotnet", "aspnetapp.dll"]
  1. Created the following .dockerignore
# directories
**/bin/
**/obj/
**/out/

# files
Dockerfile*
**/*.trx
**/*.md
**/*.ps1
**/*.cmd
**/*.sh
  1. docker build --pull -t test .

The Dockerfile built without issue. Can you try these steps and report back the results?

1
votes

I had a very similar problem

error MSB4018: NuGet.Packaging.Core.PackagingException: Unable to find fallback package folder '/usr/local/share/dotnet/sdk/NuGetFallbackFolder'.

I added RUN mkdir -p /usr/local/share/dotnet/sdk/NuGetFallbackFolder.

Then it got a lot farther but failed with a library resolution for something that I believe is just distributed with the SDK.

/usr/share/dotnet/sdk/3.1.201/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(234,5): error NETSDK1064: Package Microsoft.EntityFrameworkCore.Analyzers, version 3.1.1 was not found. It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions. 

I think the mcr.microsoft.com/dotnet/core/sdk:3.1 4/09/2010 Docker image with tags 3.1.201-buster, 3.1-buster, 3.1.201, 3.1, latest is broken.

I changed to the image based on Ubuntu bionic and it just worked again.

USE mcr.microsoft.com/dotnet/core/sdk:3.1-bionic
1
votes

I was having the same issue, after i read this link https://github.com/dotnet/sdk/issues/3059

I just appended the /restore to build command and it worked.

just like this

RUN dotnet publish --no-restore -c Release -o /app --no-cache /restore

and now it is working just fine.