Dockerize your angular app

Happy 2020 Too! If you stubmled across this post searching for how to run your uber cool angular app using docker, you are at the right place. Lets start at the begining. This is how you would normally create a new angular app:

ng new my-app

Cool! Now here is what I do with my Dockerfile:

FROM node:14-alpine as build

WORKDIR /usr/local/app

COPY ./ /usr/local/app/

RUN npm install

RUN npm run start

Now normally this will be it but I am going kick it up a notch.

I am gonna pull a pro gamer move

I am going to run my app on nginx using multi stage docker builds. This will help us run the app as if it would run on a production server:

FROM node:14-alpine as build

WORKDIR /usr/local/app

COPY ./ /usr/local/app/

RUN npm install

RUN npm run build

FROM nginx:latest

COPY --from=build /usr/local/app/dist/my-app /usr/share/nginx/html

EXPOSE 80

Thats it! Thats the post.

Photo by Ian Taylor on Unsplash