Skip to content

Commit

Permalink
Merge pull request #132 from PankajKumardev/docker-setup
Browse files Browse the repository at this point in the history
#issue 120 Add Docker Setup for Frontend and Backend
  • Loading branch information
dhairyagothi authored Oct 9, 2024
2 parents c785268 + 6a7fda0 commit 5be03e3
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 65 deletions.
1 change: 1 addition & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
2 changes: 1 addition & 1 deletion backend/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dotenv.config();

const config = {
port: process.env.PORT || 3000,
mongodbUri: process.env.MONGODB_URI,
mongodbUri: process.env.MONGODB_URI || "mongodb://localhost:27017",
jwtSecret: process.env.JWT_SECRET,
nodeEnv: process.env.NODE_ENV,
};
Expand Down
12 changes: 12 additions & 0 deletions backend/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM node:18-alpine

WORKDIR /usr/src/app

COPY package*.json ./
RUN npm install

COPY . .

EXPOSE 3000

CMD ["npm", "start"]
79 changes: 15 additions & 64 deletions backend/package-lock.json

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: '3'
services:
frontend:
build:
context: ./frontend
ports:
- "5173:5173"
volumes:
- ./frontend:/usr/src/app
- /usr/src/app/node_modules
environment:
- CHOKIDAR_USEPOLLING=true

backend:
build:
context: ./backend
ports:
- "3000:3000"
volumes:
- ./backend:/usr/src/app
- /usr/src/app/node_modules
1 change: 1 addition & 0 deletions frontend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
13 changes: 13 additions & 0 deletions frontend/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:18-alpine

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

COPY . .

EXPOSE 5173

CMD ["npm", "run", "dev"]
5 changes: 5 additions & 0 deletions frontend/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ import react from '@vitejs/plugin-react'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
server: {
port: 5173, // Ensure Vite is running on this port
host: true, // Makes the server accessible from outside the container
strictPort: true,
},
})

0 comments on commit 5be03e3

Please sign in to comment.