Dockerfile for Angular
Dockerignore
.dockerignore
node_modules
dist
.git
.gitignore
Dockerfile
.dockerignore
README.md
nginx.conf
nginx.conf
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;
}
# if you have subroutes
location ~ ^/path(?:/(.*))?$ {
root /usr/share/nginx/html;
index index.html;
try_files $uri $uri/ /path/index.html =404;
}
}
}
2 stage
- Build the Angular app using Node.js
- Serve the app using NGINX
dockerfile
FROM node:alpine AS build
WORKDIR /app
COPY . /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build --prod
FROM nginx:alpine
COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=build /app/dist/<your-app>/browser /usr/share/nginx/html
EXPOSE 80
# Start NGINX server
CMD ["nginx", "-g", "daemon off;"]