Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions mern/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.git
.gitignore
node_modules/
22 changes: 22 additions & 0 deletions mern/client/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# stage 1: build react frontend
FROM node:20-alpine AS builder

WORKDIR /app

COPY package*.json ./

RUN npm ci --ignore-scripts

COPY . .

RUN npm run build

#stage 2: serve with nginx
FROM nginx:alpine

COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=builder /app/dist /usr/share/nginx/html

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]
20 changes: 20 additions & 0 deletions mern/client/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
server {
listen 80;

# server the built react static files
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}

# proxy layer: forward all /record API requests to the backend container
location /record {
proxy_pass http://backend:5050;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
42 changes: 42 additions & 0 deletions mern/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
version: '3.8'

services:
database:
image: mongo:6-jammy
ports:
- "27017:27017"
volumes:
- mongo_data:/data/db
deploy:
resources:
limits:
memory: 512M


backend:
build: ./server
ports:
- "5050:5050"
environment:
- PORT=5050
- ATLAS_URI=mongodb://database:27017/my_mern_db
depends_on:
- database
deploy:
resources:
limits:
memory: 512M

frontend:
build: ./client
ports:
- "3000:80"
depends_on:
- backend
deploy:
resources:
limits:
memory: 256M

volumes:
mongo_data:
15 changes: 15 additions & 0 deletions mern/server/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:20-alpine

WORKDIR /app

COPY package*.json ./

RUN npm ci --omit=dev --ignore-scripts

COPY . .

USER node

EXPOSE 5050

CMD [ "npm", "start" ]