Skip to content

Commit

Permalink
Added Dockerfile and Docker Compose
Browse files Browse the repository at this point in the history
  • Loading branch information
nthskyradiated committed Oct 18, 2024
1 parent 776f537 commit 7c7e2f1
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.gitignore
dockerfile
node_modules
.git
.gitignore
*.md
dist
4 changes: 3 additions & 1 deletion ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
- Uses Zod for schema validation
- Change the values inside your .env as needed
- Change the db model as needed
- Add additional schema as needed (don't forget to add your new route handlers)
- Add additional schema as needed (don't forget to add your new route handlers)

## Added Dockerfile and Docker Compose
35 changes: 35 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

services:
mongodb:
image: mongodb/mongodb-community-server:latest
container_name: mongodb
ports:
- "27017:27017" # Expose MongoDB port
environment:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: secret
networks:
- express_api_network
volumes:
- mongodb_data:/data/db # Volume for persistent data

app:
build:
context: . # Directory containing the Dockerfile
dockerfile: dockerfile # Specify the Dockerfile name if it's not the default
container_name: express-ts-api
ports:
- "8080:8080" # Expose the app port
environment:
MONGO_URI: mongodb://admin:secret@mongodb:27017/collections?authSource=admin # Connection URI
depends_on:
- mongodb # Ensure MongoDB starts before the app
networks:
- express_api_network

networks:
express_api_network:
driver: bridge # Create a bridge network

volumes:
mongodb_data:
28 changes: 28 additions & 0 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Step 1: Use Node.js as the base image
FROM node:22-alpine
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
# Step 2: Install pnpm globally
RUN npm install -g pnpm

# Step 3: Set the working directory in the container
WORKDIR /usr/src/app

# Step 4: Copy the package.json and pnpm-lock.yaml files
COPY package.json pnpm-lock.yaml ./

# Step 5: Install the dependencies using pnpm
RUN pnpm install

# Step 6: Copy the rest of the application code
COPY . .

# Step 7: Install TypeScript and compile the TypeScript files
RUN pnpm add -g typescript
RUN tsc

# Step 8: Expose the port the app runs on (adjust if different)
EXPOSE 8080

# Step 9: Start the application
CMD ["node", "src/index.js"]

0 comments on commit 7c7e2f1

Please sign in to comment.