Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
Jammedat wants to merge 1 commit into mongodb-developer:main
base: main
Choose a base branch
Loading
from Jammedat:main
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
3 changes: 3 additions & 0 deletions mern/.dockerignore
View file Open in desktop
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
View file Open in desktop
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
View file Open in desktop
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
View file Open in desktop
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
View file Open in desktop
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" ]

AltStyle によって変換されたページ (->オリジナル) /