Skip to content

Commit a0bb44a

Browse files
committed
refactoring the dockerfile for multistage build and deployment using nginx. added a compose.yml as a working example
1 parent ad6fa24 commit a0bb44a

File tree

4 files changed

+13008
-19816
lines changed

4 files changed

+13008
-19816
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

Dockerfile

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
1-
FROM node:16
1+
# Multi-stage
2+
# 1) Node image for building frontend assets
3+
# 2) nginx stage to serve frontend assets
4+
# based on https://typeofnan.dev/how-to-serve-a-react-app-with-nginx-in-docker/
25

3-
# Create app directory
4-
WORKDIR /usr/src/app
6+
FROM node:18 AS builder
7+
WORKDIR /app
58

6-
# Install app dependencies
7-
COPY package*.json ./
9+
# Copy just package info for install
10+
COPY package*.json .
811

12+
# install node modules
913
RUN npm install
10-
# Bundle app source
14+
15+
# copy files for full build
1116
COPY . .
1217

13-
EXPOSE 3000
14-
CMD [ "npm", "start" ]
18+
# build the static content
19+
RUN npm run build
20+
21+
22+
# nginx state for serving content
23+
FROM nginx:alpine
24+
25+
WORKDIR /usr/share/nginx/html
26+
27+
# Copy static assets from builder stage
28+
COPY --from=builder /app/build .
29+
30+
# Containers run nginx with global directives and daemon off
31+
#ENTRYPOINT ["nginx", "-g", "daemon off;"]

compose.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
services:
2+
ccn-coverage-vis:
3+
build:
4+
context: .
5+
ports:
6+
- "8080:80"

0 commit comments

Comments
 (0)