Use multistage build in Dockerfile to shrink image size

Co-Authored-By: betanummeric <40263343+betanummeric@users.noreply.github.com>
This commit is contained in:
Daniel Schädler 2019-05-08 14:25:47 +02:00 committed by Felix Hamme
parent db88a42897
commit 482c500d9f
1 changed files with 9 additions and 3 deletions

View File

@ -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