From 482c500d9f4c5e31ecc375f59927278f5a0f07c4 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Wed, 8 May 2019 14:25:47 +0200 Subject: [PATCH] Use multistage build in Dockerfile to shrink image size Co-Authored-By: betanummeric <40263343+betanummeric@users.noreply.github.com> --- Dockerfile | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 25205cb..bffce91 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,19 @@ -FROM node:8-alpine - +### STAGE 1: Build ### +FROM node:8-alpine as build +WORKDIR /srv COPY js /srv/js COPY pages /srv/pages COPY static /srv/static COPY next.config.js package.json package-lock.json server.js style.css yarn.lock /srv/ -WORKDIR /srv RUN yarn install RUN yarn build +RUN yarn cache clean +### STAGE 2: Productive Container ### +FROM alpine +WORKDIR /srv +COPY --from=build /srv /srv +RUN apk --no-cache add yarn && rm -rf /var/cache/apk/* EXPOSE 80 ENV TURNIERE_API_URL=https://api.turnie.re CMD yarn start \ No newline at end of file