Home > Blockchain >  Service 'app' failed to build : Build failed
Service 'app' failed to build : Build failed

Time:06-22

I am setting up docker for my nextjs project, when I run docker-compose up I am getting the following error:

failed to load cache key: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed ERROR: Service 'app' failed to build : Build failed

Here is my Docker file:

# get NPM Packages

FROM node:16-alpine As dependecies

RUN apk add --no-cache libc6-compat

WORKDIR /app

COPY package.json package-lock.json ./
RUN npm ci --only=production

# Rebuild the source code only when needed

FROM node:16-alpine AS builder
WORKDIR /app
COPY . .
COPY --from=dependencies /app/node_modules ./node_modules
RUN npm run build

# Production image, copy all the files and run next
FROM node:16-alpine AS runner
WORKDIR /app

ENV NODE_ENV production

RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001

COPY --from=build /app .
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json

USER nextjs
EXPOSE 3000

CMD ["npm", "start"]

And here is my output.

Building app
[ ] Building 4.7s (10/20)
 => [internal] load build definition from Dockerfile                                                                                 0.0s
 => => transferring dockerfile: 846B                                                                                                 0.0s
 => [internal] load .dockerignore                                                                                                    0.0s
 => => transferring context: 2B                                                                                                      0.0s
 => [internal] load metadata for docker.io/library/node:16-alpine                                                                    2.5s
 => [auth] library/node:pull token for registry-1.docker.io                                                                          0.0s
 => CANCELED [builder 1/5] FROM docker.io/library/node:16-alpine@sha256:c785e617c8d7015190c0d41af52cc69be8a16e3d9eb7cb21f0bb58bcfca  2.2s
 => => resolve docker.io/library/node:16-alpine@sha256:c785e617c8d7015190c0d41af52cc69be8a16e3d9eb7cb21f0bb58bcfca14d6b              0.0s
 => => sha256:2408cc74d12b6cd092bb8b516ba7d5e290f485d3eb9672efc00f0583730179e8 2.80MB / 2.80MB                                       1.9s
 => => sha256:3420de6432e16fe7cbce82600d68ed72b78866b72ee631eace1c0f9a53fbef4a 2.34MB / 2.34MB                                       1.8s
 => => sha256:c785e617c8d7015190c0d41af52cc69be8a16e3d9eb7cb21f0bb58bcfca14d6b 1.43kB / 1.43kB                                       0.0s
 => => sha256:9da65f99264be2a78682095c4789b3d8cab12e0012def7d937d7125ed6e7695c 1.16kB / 1.16kB                                       0.0s
 => => sha256:97c7a05048e1e907e3cf27272002e497d945f45757bb545464d753dfd9c39e9c 6.67kB / 6.67kB                                       0.0s
 => => extracting sha256:2408cc74d12b6cd092bb8b516ba7d5e290f485d3eb9672efc00f0583730179e8                                            0.2s
 => => sha256:65b549a2824808e20e0f1ff260948c53de1cef269a02d14d769d4b210b310a35 0B / 450B                                             2.1s
 => CANCELED FROM docker.io/library/build:latest                                                                                     2.2s
 => => resolve docker.io/library/build:latest                                                                                        2.2s
 => CANCELED [internal] load build context                                                                                           2.1s
 => => transferring context: 65.16MB                                                                                                 2.1s
 => ERROR FROM docker.io/library/dependencies:latest                                                                                 2.1s
 => => resolve docker.io/library/dependencies:latest                                                                                 2.1s
 => [auth] library/dependencies:pull token for registry-1.docker.io                                                                  0.0s
 => [auth] library/build:pull token for registry-1.docker.io                                                                         0.0s
------
 > FROM docker.io/library/dependencies:latest:
------
failed to load cache key: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed
ERROR: Service 'app' failed to build : Build failed

How can I solve this?

CodePudding user response:

You've misspelled 'dependencies' in

FROM node:16-alpine As dependecies

so when the build gets to

COPY --from=dependencies /app/node_modules ./node_modules

it doesn't know what 'dependencies' is and tries to pull an image from Docker Hub called that. That doesn't exist, so the build fails.

Fixing the spelling should be enough to make it work.

  • Related