Skip to content

BlogOther

Other

Dockerize your Angular 2+ App

1 min read · Estimated time

This tutorial will help you create docker container with Angular 2 and Nginx on production mode.

1.Setup Angular 2 application

Following Angular 2 instruction and create your Angular application https://angular.io/guide/quickstart

1.1 Install the Angular CLI

1.2 Create a workspace and initial application

1.3 Serve the application

2. Setup Dockerfile

2.1 Create .dockerignore

From your root directory, create .dockerignore file. It will ignore files/folder when you copy into docker image from your source.

node_modules
npm-debug.log
Dockerfile
.dockerignore

2.2 Create Dockerfile

From your root directory, create Dockerfile

FROM node:8 as node
WORKDIR /usr/src/app
COPY package*.json ./
COPY . .
RUN npm install
RUN npm run build --prod
FROM nginx:1.13.12-alpine
COPY --from=node /usr/src/app/dist /usr/share/nginx/html
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80 443

3. Build & Run

3.1 First Build and create image

Run the following command

docker build -t zodinet/angular-web-app .

3.2 Run your image

Run the following command

docker run --name angular-web-app -p 443:443 -p 80:80 -d zodinet/angular-web-app

Check your result by visit http://localhost/

More insights from Zodinet

START WITH ZODINET

Need similar software built?

Tell us about your problem. Zodinet sends a first quote within 2 days.

Explore Zodinet

VIEN

Services

Choose the right way to deliver

See all services

Let's get started

Tell Zodinet about your problem.

Choose the way that suits you.

Send a consultation request

Contents

Jump to the part you need

  1. 1.Setup Angular 2 application
  2. 2. Setup Dockerfile
  3. 3. Build & Run
  4. 3.2 Run your image