Skip to content

Commit 0719d64

Browse files
authored
Merge pull request #929 from iitzIrFan/feature/docker-optimization
Feature/docker optimization
2 parents e3ddf07 + 3631d9d commit 0719d64

File tree

4 files changed

+60
-26
lines changed

4 files changed

+60
-26
lines changed

.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
node_modules
2+
npm-debug.log
3+
Dockerfile
4+
docker-compose.yml
5+
.dockerignore
26
.git
7+
.gitignore
8+
logs
39
.DS_Store
410
build

Dockerfile

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
1-
FROM node:20-alpine
1+
FROM node:20-alpine AS builder
22

33
WORKDIR /app
44

55
COPY package*.json ./
66

7+
# Install sharp dependencies
8+
RUN apk add --no-cache \
9+
g++ \
10+
make \
11+
python3 \
12+
libc6-compat
13+
14+
# Update npm to the latest version
15+
RUN npm install -g npm@latest
16+
717
RUN npm install --legacy-peer-deps
818

919
COPY . .
1020

11-
# No need to run 'npm run build' for development-mode Docker
21+
# Expose the application port
1222
EXPOSE 3000
1323

14-
CMD [ "npm", "run", "dev" ]
24+
# Start the application
25+
CMD ["npm", "run", "dev", "--", "--host", "0.0.0.0"]

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ services:
88
- .:/app
99
- /app/node_modules # Prevents node_modules being overwritten by the mount
1010
working_dir: /app
11-
command: npm run dev -- --host 0.0.0.0 # THIS is the crucial change for hot-reload!
11+
command: npm run dev -- --host 0.0.0.0 # Ensure the server binds to 0.0.0.0
1212
environment:
1313
- NODE_ENV=development
1414
- CHOKIDAR_USEPOLLING=true

docker-setup.md

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,57 @@
1-
# Docker Container Setup - Documentation
1+
# Docker Container Setup - Beginner-Friendly Guide
22

3-
This is the documentation on how to containerize and run the recode hive website while using Docker.
3+
This guide explains how to set up and run the Recode Hive website using Docker in the simplest way possible.
44

5-
## Prerequesites
5+
## Prerequisites
66

7-
- [Docker](https://docs.docker.com/engine/install/) installed
8-
- Docker compose installed (Optional)
7+
- Install [Docker](https://docs.docker.com/engine/install/).
8+
- Install Docker Compose (usually included with Docker Desktop).
99

1010
## Steps
1111

12-
### 1. Create a `Dockerfile` in the root directory
12+
### 1. Start the Application with Docker Compose
1313

14-
This is a text document that contains all the commands needs to build a Docker image. Basically a blue print of a docker image.
14+
The easiest way to run the application is by using Docker Compose. Simply run the following command in the project root directory:
1515

16-
Key instructions include <br>
16+
```bash
17+
docker-compose up --build
18+
```
19+
20+
This command will:
21+
- Build the Docker image.
22+
- Start the container.
23+
- Map port `3000` from the container to your local machine.
24+
25+
Once the setup is complete, visit [http://localhost:3000](http://localhost:3000) to view the site.
1726

18-
- `FROM <base_image>:<tag>` : The first instruction and specifies the base image to build upon.
19-
- `WORKDIR <path>` : Sets the working directory inside the container for subsequent instructions.
20-
- `COPY <source> <destination>` : This instruction copies files or directories from your local machine (the build context) into the Docker image.
21-
- `RUN <command>` : Executes commands during the image build process. This is used for installing dependencies, updating packages etc.
22-
- `EXPOSE <port>` : Informs docker that the container listens on the specified ports at runtime.
27+
### 2. Stop the Application
2328

24-
### 2. Build the Docker Image
29+
To stop the application, press `Ctrl+C` in the terminal where the application is running. Then, remove the containers with:
2530

2631
```bash
27-
docker build -t recodehive-app .
32+
docker-compose down
2833
```
2934

30-
This command builds the Docker image using the instructions in the Dockerfile and tags it as recodehive-app.
35+
### 3. Debugging Tips
3136

32-
### 3. Run the Container
37+
- **View Logs:** If you encounter issues, check the container logs:
38+
```bash
39+
docker-compose logs
40+
```
41+
- **Rebuild the Image:** If you make changes to the code, rebuild the image:
42+
```bash
43+
docker-compose up --build
44+
```
45+
- **Access the Container Shell:** To debug inside the container:
46+
```bash
47+
docker exec -it <container_name> sh
48+
```
3349

34-
```bash
35-
docker run -p 3000:3000 recodehive-app
36-
```
50+
### Notes
51+
52+
- The `docker-compose.yml` file is pre-configured for development.
53+
- The application is set to bind to `0.0.0.0` for external access.
54+
- File changes on your local machine will automatically reflect in the container (hot-reloading enabled).
3755

38-
This runs the container and maps port 3000 from the container to your local machine. <br>
39-
Now Visit http://localhost:3000 to view the site.
56+
For more details, refer to the official Docker documentation.
4057

0 commit comments

Comments
 (0)