Dockerize your Angular Application

Create a Docker image of your Angular application using Nginx

Image for post
Image for post
Photo by Andy Li on Unsplash

Create an Angular application

$ ng new angular-docker --style==scss --routing=true

Add a Dockerfile

$ touch Dockerfile
FROM node:10.21.0-alpine as builder
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . .
RUN npm run build --prod
FROM nginx:1.16.0-alpine as server
COPY --from=builder /app/dist/angular-docker /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

Build the Docker image

$ docker build -t angular-docker -f Dockerfile .

List Docker images

$ docker images
Image for post
Image for post

Run the Docker image

$ docker run -ti --rm -p 8080:80 angular-docker
Image for post
Image for post

Written by

I develop software by profession. My interests include: history, economics, politics & enterprise-architecture. I am a child of God.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store