How to cache a layer manually in Dockerfile

32 views Asked by At

I'm trying to rebuild a docker image, I modified the source code in index.js.

The dockerfile:

FROM node:20

WORKDIR /usr/src/app

COPY . .

RUN npm install

EXPOSE 3000

CMD ["node", "index.js"]

Since I modified the code in index.js the the layer (copy . . ) in the Dockerfile is uncached, so the upcoming layers will also become uncached. Is there any possible way that I can modify the Dockerfile, If the package.json is not modified then I want the RUN npm install layer to be cached.

I'm a beginner in docker I need a suggesion to implement my problem

0

There are 0 answers