Skip to content

Instantly share code, notes, and snippets.

@alaboudi
Created October 14, 2017 03:51
Show Gist options
  • Save alaboudi/44cc6baff74fd74f2bc2e08a7c9bee90 to your computer and use it in GitHub Desktop.
Save alaboudi/44cc6baff74fd74f2bc2e08a7c9bee90 to your computer and use it in GitHub Desktop.
Docker file for Angular4 application on an Nginx server
# This docker file will consist of two stages. The first stage will be used to arrange the application
# dependencies and compile it. The second stage will be used to set up an nginx server to serve the
# static angular content.
### Stage 1: Downloading application dependencies and compiling angular AoT
# Create image based on the official Node based on the Alpine linus distribution image from dockerhub
FROM node:alpine AS builder
# Create a directory where our app will be placed. -p is to create parent directories as necessary
RUN mkdir -p /usr/src/app
# Change directory so that our commands run inside this new directory.
WORKDIR /usr/src/app
# Copy dependency definitions
COPY package.json .
# Install dependecies
RUN npm install
# Get all the code needed to run the app
COPY . .
# Build the application. This will create a static application in the 'dist' directory
RUN $(npm bin)/ng build --prod --build-optimizer
### Stage 2: Set up nginx server and refer to artifact output from first stage
# Create a new container from the nginx image
FROM nginx:alpine
## Remove default nginx website
RUN rm -rf /usr/share/nginx/html/*
# Copy static compiled output from first stage to the designated nginx directory
COPY --from=builder /usr/src/app/dist /usr/share/nginx/html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment