-
Notifications
You must be signed in to change notification settings - Fork 336
chore: add Dockerfile and docker-compose for local development #52
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
Open
+102
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
mern/.dockerignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" ] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.