Skip to content

Commit 84dafd6

Browse files
committed
feat: ✨ add Docker support for containerizing the application with Nginx
1 parent 7d07818 commit 84dafd6

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

Dockerfile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Use the official Node.js runtime as the base image
2+
FROM node:20 as build
3+
4+
# Set the working directory in the container
5+
WORKDIR /app
6+
7+
# Copy package.json and yarn.lock to the working directory
8+
COPY package.json yarn.lock ./
9+
10+
# Install dependencies
11+
RUN yarn install
12+
13+
# Copy the entire application code to the container
14+
COPY . .
15+
16+
# Set environment variables for production
17+
ENV VITE_APP_DEBUG=false
18+
19+
# Build the React app for production
20+
RUN yarn build
21+
22+
# Use Nginx as the production server
23+
FROM nginx:alpine
24+
25+
# Copy the built React app to Nginx's web server directory
26+
COPY --from=build /app/dist /usr/share/nginx/html
27+
28+
# Copy the Nginx configuration file to the container
29+
COPY nginx.conf /etc/nginx/nginx.conf
30+
31+
# Expose port 80 for the Nginx server
32+
EXPOSE 80
33+
34+
# Start Nginx when the container runs
35+
CMD ["nginx", "-g", "daemon off;"]

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This template is built using the official Vite template for React with TypeScrip
1212
- [Prettier](https://prettier.io/) for code formatting.
1313
- [Husky](https://typicode.github.io/husky/#/) for Git hooks to automate tasks such as linting, formatting, and testing before commits.
1414
- CI (Continuous Integration) setup with [GitHub Actions](https://github.com/features/actions) for automated testing and building.
15+
- Docker support for containerizing the application.
1516

1617
## Project Structure
1718

nginx.conf

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
user nginx;
2+
worker_processes auto;
3+
error_log /var/log/nginx/error.log warn;
4+
pid /var/run/nginx.pid;
5+
6+
events {
7+
worker_connections 1024;
8+
}
9+
10+
http {
11+
include /etc/nginx/mime.types;
12+
default_type application/octet-stream;
13+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
14+
'$status $body_bytes_sent "$http_referer" '
15+
'"$http_user_agent" "$http_x_forwarded_for"';
16+
access_log /var/log/nginx/access.log main;
17+
sendfile on;
18+
19+
keepalive_timeout 65;
20+
21+
server {
22+
listen 80;
23+
24+
location / {
25+
root /usr/share/nginx/html;
26+
index index.html index.htm;
27+
try_files $uri $uri/ /index.html;
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)