Build and run Angular application in a Docker container

Photo by Alice Achterhof on Unsplash
$ git clone https://github.com/wkrzywiec/aston-villa-app.git
$ ng build --prod
FROM nginx:1.17.1-alpine
COPY nginx.conf /etc/nginx/nginx.conf
COPY /dist/aston-villa-app /usr/share/nginx/html
events{}http {    include /etc/nginx/mime.types;    server {        listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}
}
$ docker build -t av-app-image .
$ docker image lsREPOSITORY    TAG            IMAGE ID      
av-app-image latest a160a7494a19
nginx 1.17.1-alpine ea1193fd3dde
$ docker run --name av-app-container -d -p 8080:80 av-app-image
$ docker container lsCONTAINER ID  IMAGE         STATUS         NAMES
2523d9f77cf6 av-app-image Up 26 minutes av-app-container
FROM node:12.7-alpine AS build
WORKDIR /usr/src/app
COPY package.json package-lock.json ./
RUN npm install
COPY . .
RUN npm run build
dist
node_modules
### STAGE 1: Build ###
FROM node:12.7-alpine AS build
WORKDIR /usr/src/app
COPY package.json package-lock.json ./
RUN npm install
COPY . .
RUN npm run build
### STAGE 2: Run ###
FROM nginx:1.17.1-alpine
COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=build /usr/src/app/dist/aston-villa-app /usr/share/nginx/html
$ docker build -t av-app-multistage-image .
$ docker run --name av-app-multistage-container -d -p 8888:80 av-app-multistage-image

--

--

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