Skip to content

Commit

Permalink
Merge pull request #52 from arnab2001/dockerize
Browse files Browse the repository at this point in the history
nginx docker prod
  • Loading branch information
arnab2001 authored Feb 7, 2024
2 parents 9a47372 + 748fd63 commit 8f8066b
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 10 deletions.
3 changes: 3 additions & 0 deletions client/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
build
npm-debug.log
40 changes: 30 additions & 10 deletions client/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,41 @@
# Build react client
FROM node:16-alpine
FROM node:lts-alpine as build

# Working directory be app
WORKDIR /usr/src/app
WORKDIR /app

COPY package*.json ./

### Installing dependencies
RUN npm ci

RUN npm install --silent

# copy local files to app folder
COPY . .

EXPOSE 3000
RUN npm run build
FROM nginx:latest as prod

COPY --from=build /app/build /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf

EXPOSE 80/tcp

CMD ["/usr/sbin/nginx", "-g", "daemon off;"]

# # Build react client
# FROM node:16-alpine

# # Working directory be app
# WORKDIR /usr/src/app

# COPY package*.json ./

# ### Installing dependencies

# RUN npm install --silent

# # copy local files to app folder
# COPY . .

# EXPOSE 3000

CMD ["npm","start"]
# CMD ["npm","start"]

# docker build -t arnabchat2001/client .
# docker tag arnabchat2001/client arnabchat2001/client:v2
Expand Down
29 changes: 29 additions & 0 deletions client/Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Use the official Node.js runtime as the base image
FROM node:18 as build

# Set the working directory in the container
WORKDIR /app

# Copy package.json and package-lock.json to the working directory
COPY package*.json ./

# Install dependencies
RUN npm install

# Copy the entire application code to the container
COPY . .

# Build the React app for production
RUN npm run build

# Use Nginx as the production server
FROM nginx:alpine

# Copy the built React app to Nginx's web server directory
COPY --from=build /app/build /usr/share/nginx/html

# Expose port 80 for the Nginx server
EXPOSE 80

# Start Nginx when the container runs
CMD ["nginx", "-g", "daemon off;"]
29 changes: 29 additions & 0 deletions client/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
http {

include mime.types;

set_real_ip_from 0.0.0.0/0;
real_ip_recursive on;
real_ip_header X-Forward-For;
limit_req_zone $binary_remote_addr zone=mylimit:10m rate=10r/s;

server {
listen 80;
server_name localhost;
root /proxy;
limit_req zone=mylimit burst=70 nodelay;

location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri /index.html;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}

events {}
1 change: 1 addition & 0 deletions server/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package-lock.json
/server/public
# misc
.DS_Store

.env
.env.local
.env.development.local
Expand Down

0 comments on commit 8f8066b

Please sign in to comment.