Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: #42 Add Dockerfile and docker-compose for containerization #43

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
9 changes: 9 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM node:lts-slim

WORKDIR /app

COPY package*.json .
RUN npm install
COPY . .
EXPOSE 3000
CMD [ "npm", "run", "server" ]
17 changes: 17 additions & 0 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM node:lts-slim AS build

WORKDIR /app

COPY package*.json .
RUN npm install
COPY . .

FROM node:lts-slim AS production

WORKDIR /app

COPY --from=build /app /app/

EXPOSE 3000

CMD [ "npm", "run", "server" ]
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,26 @@ To run only the backend:
```bash
npm run server
```
# Docker for developement(optional)
```
docker-compose up --build
```
```
docker-compose down
```
# Docker for production
Modify docker-compose.yml

Change the dockerfile line in the build section to Dockerfile.prod:

```
services:
app:
build:
context: .
dockerfile: Dockerfile.prod # Use the production Dockerfile
...
```

## Build & Deploy

Expand Down
41 changes: 41 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
services:
app:
build:
context: .
dockerfile: Dockerfile.dev
ports:
- "${PORT}:${PORT}"
environment:
- NODE_ENV=${NODE_ENV}
- PORT=${PORT}
- JWT_SECRET=${JWT_SECRET}
- RAZORPAY_KEY_ID=${RAZORPAY_KEY_ID}
- RAZORPAY_KEY_SECRET=${RAZORPAY_KEY_SECRET}
- PAGINATION_MAX_LIMIT=${PAGINATION_MAX_LIMIT}
- EMAIL_HOST=${EMAIL_HOST}
- EMAIL_PORT=${EMAIL_PORT}
- EMAIL_USER=${EMAIL_USER}
- EMAIL_PASS=${EMAIL_PASS}
- EMAIL_FROM=${EMAIL_FROM}
restart: always
depends_on:
- mongo
networks:
- backend

mongo:
image: mongo:latest
ports:
- "27017:27017"
volumes:
- mongo_data:/data/db
restart: always
networks:
- backend

volumes:
mongo_data:

networks:
backend:
driver: bridge