Reputation: 100010
I have this idea that I haven't completed yet. In a Dockerfile I have:
FROM node:10
WORKDIR /app
RUN "*cache node modules here*"
RUN e.g. npm cache add foo bar baz
COPY package.json .
RUN npm i --cache-min 9999999 --loglevel=warn
COPY . .
CMD node dist
How can I create ultra high-performance Dockerfiles by caching some Node.js modules/package before the npm install step?
Is there some trick that can do this?
Upvotes: 4
Views: 4391
Reputation: 158898
This is out-of-the-box Docker functionality. If your Dockerfile says
FROM node:10
WORKDIR /app
COPY package.json .
RUN npm install
COPY ...
then, if the package.json
hasn't changed, Docker will skip over the RUN npm install
step and use the filesystem image that results from doing it.
Upvotes: 6