简体   繁体   中英

Docker build fails for NestJs service

I have created a nestJS rest api. below is the docker file that I'm using to build the service.

FROM node:alpine3.16 AS development
WORKDIR /usr/src/app
COPY --chown=node:node package*.json ./
RUN npm ci
COPY --chown=node:node . .
RUN npm run build
ENV NODE_ENV production
RUN npm ci --only=production --omit=dev && npm cache clean --force

FROM node:alpine3.16 AS production
WORKDIR /app
COPY --chown=node:node --from=build /usr/src/node_modules ./node_modules
COPY --chown=node:node --from=build /usr/src/app/dist ./dist
USER node

# start the server using the production build
CMD [ "node", "dist/main.js" ]

On running the docker build this is the output that I receive. as you can see it fails to copy node_modules folder. I'm not sure if that is the real problem or something else is wrong in the dockerfile

Sending build context to Docker daemon  320.4MB
Step 1/16 : FROM node:alpine3.16 AS development
 ---> fbf8faa0b327
Step 2/16 : WORKDIR /usr/src/app
 ---> Using cache
 ---> 9586fc2253da
Step 3/16 : COPY --chown=node:node package*.json ./
 ---> Using cache
 ---> 170ae630fdff
Step 4/16 : RUN npm ci
 ---> Using cache
 ---> 1fd94efbfebb
Step 5/16 : COPY --chown=node:node . .
 ---> 0b8a645d4548
Step 6/16 : USER root
 ---> Running in e7882157586e
Removing intermediate container e7882157586e
 ---> b3ecda575e47
Step 7/16 : RUN npm run build
 ---> Running in 020d3ecc7f2a

> service@0.0.1 prebuild
> rimraf dist


> service@0.0.1 build
> nest build

webpack 5.72.1 compiled successfully in 6222 ms
Removing intermediate container 020d3ecc7f2a
 ---> abe9a1016a92
Step 8/16 : ENV NODE_ENV production
 ---> Running in eda90aa82fd5
Removing intermediate container eda90aa82fd5
 ---> 69070cf4854e
Step 9/16 : RUN npm ci --only=production --omit=dev && npm cache clean --force
 ---> Running in bcbceed9f0b0
npm WARN config only Use `--omit=dev` to omit dev dependencies from the install.
npm WARN deprecated multer@1.4.4: Multer 1.x is affected by CVE-2022-24434. This is fixed in v1.4.4-lts.1 which drops support for versions of Node.js before 6. Please upgrade to at least Node.js 6 and version 1.4.4-lts.1 of Multer. If you need support for older versions of Node.js, we are open to accepting patches that would fix the CVE on the main 1.x release line, whilst maintaining compatibility with Node.js 0.10.

added 260 packages, and audited 261 packages in 19s

23 packages are looking for funding
  run `npm fund` for details

6 high severity vulnerabilities

To address all issues (including breaking changes), run:
  npm audit fix --force

Run `npm audit` for details.
npm WARN using --force Recommended protections disabled.
Removing intermediate container bcbceed9f0b0
 ---> f42e890665f0
Step 10/16 : FROM node:alpine3.16 AS production
 ---> fbf8faa0b327
Step 11/16 : WORKDIR /app
 ---> Using cache
 ---> bcd15d86cb7e
Step 12/16 : USER root
 ---> Running in 9d97f5cc54dd
Removing intermediate container 9d97f5cc54dd
 ---> cd1f956a6c91
Step 13/16 : COPY --chown=node:node --from=build /usr/src/app/node_modules ./node_modules
invalid from flag value build: pull access denied for build, repository does not exist or may require 'docker login': denied: requested access to the resource is denied

What is causing the problem and how can I resolve it?

There is no build stage in your docker steps. You probably mean --from=development instead of --from=build

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM