Skip to content

Commit 9ed6f44

Browse files
fix: update Dockerfile for multi-stage build and add Docker usage instructions to README
1 parent e594340 commit 9ed6f44

File tree

2 files changed

+56
-9
lines changed

2 files changed

+56
-9
lines changed

Dockerfile

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,35 @@
1-
# Step 1: Specify the base image
2-
FROM node:22
1+
# Step 1: Build stage
2+
FROM node:22-alpine AS builder
33

4-
# Step 2: Set the working directory inside the container
4+
# Set the working directory
55
WORKDIR /app
66

7-
# Step 3: Copy package.json and package-lock.json files
7+
# Copy package.json and package-lock.json
88
COPY package*.json ./
99

10-
# Step 4: Install dependencies
10+
# Install dependencies
1111
RUN npm install
1212

13-
# Step 5: Copy the rest of the application code
13+
# Copy the rest of the application code
1414
COPY . .
1515

16-
# Step 6: Expose the port the application runs on
16+
# Build the application
17+
RUN npm run build
18+
19+
# Step 2: Production stage
20+
FROM node:22-alpine
21+
22+
# Set the working directory
23+
WORKDIR /app
24+
25+
# Copy only the built application and necessary files from the builder stage
26+
COPY --from=builder /app/package*.json ./
27+
COPY --from=builder /app/node_modules ./node_modules
28+
COPY --from=builder /app/.next ./.next
29+
COPY --from=builder /app/public ./public
30+
31+
# Expose the port the application runs on
1732
EXPOSE 3000
1833

19-
# Step 7: Define the command to run the application
20-
CMD ["npm","run","dev"]
34+
# Define the command to start the application
35+
CMD ["npm", "start"]

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,38 @@ To start your development server run:
6262
pnpm dev
6363
```
6464

65+
## 🐳 Using Docker
66+
67+
### 1. Build the Image
68+
Run in the project root:
69+
```bash
70+
docker build -t papers-codechef .
71+
```
72+
73+
### 2. Run the Container
74+
Start the app with:
75+
```bash
76+
docker run -p 3000:3000 papers-codechef
77+
```
78+
Access it at `http://localhost:3000`.
79+
80+
### 3. Environment Variables
81+
Ensure `.env` is configured. Use `--env-file` to pass it:
82+
```bash
83+
docker run --env-file .env -p 3000:3000 papers-codechef
84+
```
85+
86+
### 4. Stop & Clean Up
87+
Stop the container:
88+
```bash
89+
docker ps
90+
docker stop <CONTAINER ID>
91+
```
92+
Remove the image:
93+
```bash
94+
docker rmi papers-codechef
95+
```
96+
6597
Before getting started, please ensure that the .env file is properly configured. The .env.example file has been provided for your reference, with examples of environment variables to be listed.
6698

6799
## License

0 commit comments

Comments
 (0)