From 5b7f291c3ade5a81eefb9d53ee265416953fbf15 Mon Sep 17 00:00:00 2001 From: Til Schneider Date: Fri, 21 May 2021 17:09:08 +0200 Subject: [PATCH] Make subsequent calls of `npm run docker` faster This makes subsequent calls of `npm run docker` a lot faster if source code was changed. How it works: - The build step only executes `npm install`. So it only needs the `package.json` file. - By copying the whole project folder as late as possible, docker can use cached layers for all previous steps. This includes long-running steps like `apt-get` and `npm install`. --- Dockerfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7b70733..3ebb504 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,7 @@ RUN export DEBIAN_FRONTEND=noninteractive \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* -COPY . /usr/src/app +COPY package.json /usr/src/app/package.json ENV NODE_ENV="production" @@ -37,7 +37,9 @@ RUN export DEBIAN_FRONTEND=noninteractive \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* -COPY --from=builder /usr/src/app /app +RUN mkdir /app +COPY --from=builder /usr/src/app/node_modules /app/node_modules +COPY . /app ENV NODE_ENV="production" ENV CHOKIDAR_USEPOLLING=1