Skip to content

Commit 8d59ea9

Browse files
committed
#20 dockerize the angular application with nginx
1 parent 95a35ee commit 8d59ea9

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.git
2+
.editorconfig
3+
/.vscode/*
4+
/node_modules
5+
/e2e
6+
/docs
7+
.gitignore
8+
*.zip

Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# From the source https://dev.to/oneofthedevs/docker-angular-nginx-37e4
2+
3+
FROM node:20-alpine AS build
4+
5+
WORKDIR /dist/src/app
6+
7+
RUN npm cache clean --force
8+
COPY . .
9+
RUN npm install
10+
RUN npm run build
11+
12+
13+
### STAGE 2:RUN ###
14+
# Defining nginx image to be used
15+
FROM nginx:latest AS ngi
16+
# Copying compiled code and nginx config to different folder
17+
# NOTE: This path may change according to your project's output folder
18+
COPY --from=build /dist/src/app/dist/angular-spa /usr/share/nginx/html
19+
COPY /nginx.conf /etc/nginx/conf.d/default.conf
20+
# Exposing a port, here it means that inside the container
21+
# the app will be using Port 80 while running
22+
EXPOSE 80

nginx.conf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
server {
2+
listen 80;
3+
sendfile on;
4+
default_type application/octet-stream;
5+
6+
gzip on;
7+
gzip_http_version 1.1;
8+
gzip_disable "MSIE [1-6]\.";
9+
gzip_min_length 256;
10+
gzip_vary on;
11+
gzip_proxied expired no-cache no-store private auth;
12+
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
13+
gzip_comp_level 9;
14+
15+
root /usr/share/nginx/html;
16+
17+
location / {
18+
try_files $uri $uri/ /index.html =404;
19+
}
20+
}

0 commit comments

Comments
 (0)