Home > Blockchain >  DotNet failing Docker build
DotNet failing Docker build

Time:10-13

I have a longtime Dockerfile that worked just fine. Then recently I started getting build errors:

FROM microsoft/dotnet:sdk AS build-env
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY MycompanyDAL/*.csproj ./
COPY MycompanyDAL/NuGet.config ./
RUN dotnet restore

# Copy everything else and build
COPY MycompanyDAL/. ./
RUN dotnet publish -c Release -o out

# Build runtime image

FROM microsoft/dotnet:aspnetcore-runtime
WORKDIR /app
COPY --from=build-env /app/out .

ENV ASPNETCORE_URLS=http:// :8080
ENTRYPOINT ["dotnet", "MycompanyDAL.dll"]

which gave the errors:

   docker build -t icverify-data-access .
[ ] Building 1.4s (5/5) FINISHED                                                                                                                                                                          
 => [internal] load build definition from Dockerfile                                                                                                                                                 0.0s
 => => transferring dockerfile: 512B                                                                                                                                                                 0.0s
 => [internal] load .dockerignore                                                                                                                                                                    0.0s
 => => transferring context: 139B                                                                                                                                                                    0.0s
 => CANCELED [internal] load metadata for docker.io/microsoft/dotnet:aspnetcore-runtime                                                                                                              1.2s
 => ERROR [internal] load metadata for docker.io/microsoft/dotnet:sdk                                                                                                                                1.2s
 => [auth] microsoft/dotnet:pull token for registry-1.docker.io                                                                                                                                      0.0s
------
 > [internal] load metadata for docker.io/microsoft/dotnet:sdk:
------
failed to solve with frontend dockerfile.v0: failed to create LLB definition: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed

I then updated to:

FROM mcr.microsoft.com/dotnet/runtime AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk AS build
WORKDIR /src

#FROM mcr.microsoft.com/dotnet/sdk:5.0.10 AS build-env
#WORKDIR /app

# Copy csproj and restore as distinct layers
COPY MycompanyDAL/*.csproj ./
COPY MycompanyDAL/NuGet.config ./
RUN dotnet restore

# Copy everything else and build
FROM base AS publish
COPY MycompanyDAL/. ./
RUN dotnet publish -c Release -o out


# Build runtime image

FROM base AS final
WORKDIR /app
COPY --from=base /app/out .

ENV ASPNETCORE_URLS=http:// :8080
ENTRYPOINT ["dotnet", "MycompanyDAL.dll"]

But this gives the same error. I am able to pull those mcr manually but it doesn't fix the problem:

docker pull mcr.microsoft.com/dotnet/sdk:5.0

CodePudding user response:

There are a number of issues with your Dockerfile which I've fixed here

FROM mcr.microsoft.com/dotnet/aspnet AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk AS build
WORKDIR /src

# Copy csproj and restore as distinct layers
COPY MycompanyDAL/*.csproj ./
COPY MycompanyDAL/NuGet.config ./
RUN dotnet restore

# Copy everything else and build
FROM build AS publish
COPY MycompanyDAL/. ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM base AS final
WORKDIR /app
COPY --from=publish /src/out .

ENV ASPNETCORE_URLS=http:// :8080
ENTRYPOINT ["dotnet", "MycompanyDAL.dll"]
  • Related