Skip to content

Fixing "pull access denied" Docker Build Errors ​

When building Docker images, you may encounter "pull access denied" or "insufficient_scope: authorization failed" errors. These can occur for various reasons, from authentication issues to incorrect image references and platform mismatches.

Problem Analysis ​

The error typically appears when Docker cannot access the specified image or repository:

failed to load cache key: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed

This can happen when:

  1. Referencing non-existent stages in multi-stage builds
  2. Using incorrect image names or repositories
  3. Facing authentication/authorization issues
  4. Encountering platform architecture mismatches

Solutions ​

1. Fix Multi-Stage Build References ​

The most common cause is incorrect stage references in multi-stage Dockerfiles. In the provided Dockerfile, the issue is:

dockerfile
# Incorrect - references non-existent stage "publish/app"
COPY --from=publish/app /app .

The correct approach references an existing build stage:

dockerfile
# Correct - references the "build" stage that exists
COPY --from=build /app .
Complete Fixed Dockerfile
dockerfile
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["src/App.Web/App.Web.csproj", "src/App.Web/"]
RUN dotnet restore "App.Web.csproj"
COPY . .
WORKDIR "/src/App.Web"
RUN dotnet build App.Web.csproj -c Debug -o /app

FROM build as debug
RUN dotnet publish "App.Web.csproj" -c Debug -o /app

FROM base as final
WORKDIR /app
# Fixed: references existing "build" stage instead of "publish/app"
COPY --from=build /app .
ENTRYPOINT ["dotnet","App.Web.dll"]

2. Update Outdated Image References ​

Microsoft has renamed many of their .NET Docker repositories. Update outdated references:

dockerfile
# Old (may cause issues)
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim

# Updated (recommended)
FROM mcr.microsoft.com/dotnet/aspnet:3.1-buster-slim

3. Handle Platform Architecture Mismatches ​

If you're on a different architecture (like Apple Silicon M1/M2), explicitly specify the platform:

bash
docker build . --platform linux/amd64

This forces Docker to pull the correct architecture version of base images.

4. Verify Docker Authentication ​

Ensure you're authenticated with the appropriate registry:

bash
docker login

Then retry your build command:

bash
docker build .

Best Practices ​

TIP

  • Always verify stage names match exactly between FROM and COPY --from statements
  • Use official, up-to-date image references from verified sources
  • Consider platform compatibility when building across different systems
  • Regularly update your Dockerfiles as repositories and image names change

Troubleshooting Steps ​

  1. Check stage names: Ensure all COPY --from statements reference valid build stages
  2. Verify image availability: Test pulling base images directly with docker pull
  3. Review repository URLs: Confirm image repositories haven't been renamed or moved
  4. Check platform compatibility: Use --platform flag if building across different architectures

By addressing these common issues, you can resolve "pull access denied" errors and successfully build your Docker images.