Codementor Events

Angular + Docker: Dockerize your app in 5 minutes! (video included)

Published Oct 26, 2018Last updated Nov 01, 2018
Angular + Docker: Dockerize your app in 5 minutes! (video included)

Taking an angular application into production can be daunting enough as it is. This is a simple, straight-forward, guide that will have you running your application inside of a docker container in 5-minutes flat.

We’ll use an node.js container to build your application but then move over into an nginx container to serve the final product. It’s a common misconception that running your production built application from a node.js http server is the right way to go. Please do not do this.

By moving into an nginx container we copy only your dist directory and leave everything else behind!

https://www.youtube.com/watch?v=iHPErFiOV-o?ecver=2

Dockerfile

First, place this Dockerfile in your applications root directory:

FROM node:alpine AS builder

WORKDIR /app

COPY . .

RUN npm install && \
    npm run build

FROM nginx:alpine

COPY --from=builder /app/dist/* /usr/share/nginx/html/

Docker Commands

Now build your docker image:

$ docker build -t my-angular-app:v1 .

Then run it!

$ docker run -p 80:80 my-angular-app:v1

See more at https://matthewdavis.io

Discover and read more posts from Matthew Davis
get started
post commentsBe the first to share your opinion
Chakradhar V
4 years ago

It’s a common misconception that running your production built application from a node.js http server is the right way to go. Please do not do this.

Can you elaborate more on this ?

Vlado Tesanovic
5 years ago

Instead of

COPY --from=builder /app/dist/* /usr/share/nginx/html/

do

COPY --from=builder /app/dist/ /usr/share/nginx/html/

Matthew Mulhearn
5 years ago

why would you make a video with purple text on a black background

Show more replies