Skip to content

Commit 19b4191

Browse files
committed
Add Docker configuration for backend and frontend services
1 parent f618813 commit 19b4191

5 files changed

Lines changed: 81 additions & 0 deletions

File tree

Back-end/.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
.git
3+
.env
4+
dist

Back-end/Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM node:24-alpine
2+
3+
WORKDIR /app
4+
5+
6+
RUN corepack enable
7+
8+
9+
COPY package.json pnpm-lock.yaml ./
10+
11+
12+
RUN pnpm install --frozen-lockfile
13+
14+
15+
COPY . .
16+
17+
EXPOSE 3000
18+
19+
CMD ["pnpm", "start"]

Front-end/.dockerignore

Whitespace-only changes.

Front-end/Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# ---- Build Stage ----
2+
FROM node:24-slim AS build
3+
4+
WORKDIR /app
5+
6+
# pnpm setup
7+
ENV PNPM_HOME="/pnpm"
8+
ENV PATH="$PNPM_HOME:$PATH"
9+
RUN corepack enable
10+
11+
# Copy dependency files first (cache optimization)
12+
COPY package.json pnpm-lock.yaml ./
13+
14+
RUN pnpm install --frozen-lockfile
15+
16+
# Copy source code
17+
COPY . .
18+
19+
# Build (Vite to /dist)
20+
RUN pnpm build
21+
22+
# ---- Production Stage ----
23+
FROM nginx:alpine
24+
25+
COPY --from=build /app/dist /usr/share/nginx/html
26+
27+
EXPOSE 80
28+
29+
CMD ["nginx", "-g", "daemon off;"]

docker-compose.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
services:
2+
backend:
3+
build:
4+
context: ./Back-end
5+
dockerfile: Dockerfile
6+
container_name: mern-backend
7+
restart: always
8+
env_file:
9+
- ./Back-end/.env
10+
ports:
11+
- "3000:3000"
12+
networks:
13+
- mern-network
14+
15+
frontend:
16+
build:
17+
context: ./Front-end
18+
dockerfile: Dockerfile
19+
container_name: mern-frontend
20+
restart: always
21+
ports:
22+
- "80:80"
23+
depends_on:
24+
- backend
25+
networks:
26+
- mern-network
27+
28+
networks:
29+
mern-network:

0 commit comments

Comments
 (0)