Friday, 20 July 2018

How to create smaller docker images with multi-stage build

Here I will show you the example for creating least possible docker images with the help of Docker Multi-Stage build feature.

Below is a sample for Angular 6 application, which creates production build (docker image) from source-code

Dockerfile:

# Stage 0, based on Node.js, to build and compile Angular app

FROM node:10.4.1-alpine as node

WORKDIR /app

COPY package.json /app/

RUN npm i

COPY ./ /app/

RUN npm run build -- --prod

# Stage 1, based on Nginx, to have only the compiled app, ready for production with Nginx

FROM nginx:1.15.0-alpine

COPY --from=node /app/dist/test-app  /usr/share/nginx/html

COPY ./nginx-custom.conf  /etc/nginx/conf.d/default.conf

No comments:

Post a Comment