Skip to content

Commit bdf7bd1

Browse files
committed
Update docker setup
1 parent fc22d33 commit bdf7bd1

3 files changed

Lines changed: 78 additions & 23 deletions

File tree

Dockerfile

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
FROM node:20-alpine
1+
FROM node:18-alpine
2+
23
WORKDIR /usr/server
3-
COPY package*.json .
4-
RUN npm ci --only=production
4+
5+
COPY package*.json ./
6+
7+
RUN npm ci --only=production && npm cache clean --force
8+
59
COPY . .
6-
EXPOSE 8000
7-
EXPOSE 8001
8-
EXPOSE 8002
10+
11+
EXPOSE 8000 8001 8002
12+
13+
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
14+
CMD node -e "require('http').get('http://localhost:8000/health', (res) => { process.exit(res.statusCode === 200 ? 0 : 1) }).on('error', () => process.exit(1))"
15+
916
CMD ["node", "server.js"]

README.md

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,66 @@ let's start with
5252

5353
## Usage
5454

55-
- You need node.js 18.x or 20.x
55+
- You need Node.js 18.x or higher (24.x preferred)
5656
- Fork and clone this repository (optionally subscribe to repo changes)
5757
- Run `npm i` to install dependencies and generate RSA certificate
5858
- Remove unneeded dependencies if your project doesn't require them
5959
- Add your license to `LICENSE` file but don't remove starter kit license
6060
- Start your project modifying this starter kit
61-
- If you have Docker and Docker Compose installed to run the project, use the command: `docker-compose up`
61+
## Docker Usage
62+
63+
The easiest way to run this application is using Docker and Docker Compose:
64+
65+
### Prerequisites
66+
67+
- Docker and Docker Compose installed
68+
- No need to install PostgreSQL or Redis locally
69+
- Uses PostgreSQL 17 (latest stable) and Redis 8
70+
71+
### Quick Start
72+
73+
```bash
74+
# Start all services (API, PostgreSQL, Redis)
75+
docker-compose up
76+
77+
# Start services in background (detached mode)
78+
docker-compose up -d
79+
80+
# Stop all services
81+
docker-compose down
82+
83+
# View logs
84+
docker-compose logs
85+
86+
# View logs for specific service
87+
docker-compose logs api-example
88+
docker-compose logs pg-example
89+
docker-compose logs redis-example
90+
91+
# Rebuild and start services
92+
docker-compose up --build -d
93+
```
94+
95+
### Access Points
96+
- **Main Application**: http://localhost:8002/ (Metarhia Console)
97+
- **API Endpoints**: http://localhost:8001/api/
98+
- **Load Balancer**: http://localhost:8000/ (redirects to 8002)
99+
100+
### Service Status
101+
102+
```bash
103+
# Check running services
104+
docker-compose ps
105+
106+
# Restart a specific service
107+
docker-compose restart api-example
108+
```
109+
110+
## Manual Installation (Alternative)
111+
112+
If you prefer to run without Docker:
62113
- Before running server initialize the DB:
63-
- First of all, make sure you have PostgreSQL installed (preferably 12.x to 16.x).
114+
- First of all, make sure you have PostgreSQL installed (preferably 15.x to 17.x).
64115
- Run database initialization script: `database/setup.sh`
65116
- Run project: `node server.js` and stop with Ctrl+C
66117
- Ask questions in Telegram https://t.me/nodeua (node.js related) or

docker-compose.yml

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: '3'
2-
31
services:
42
api-example:
53
build:
@@ -9,39 +7,38 @@ services:
97
environment:
108
- DB_HOST=pg-example
119
- REDIS_HOST=redis-example
12-
volumes:
13-
- ./application:/usr/server/application
1410
depends_on:
1511
- pg-example
1612
- redis-example
1713
ports:
18-
- 127.0.0.1:8000:8000
19-
- 127.0.0.1:8001:8001
20-
- 127.0.0.1:8002:8002
14+
- "127.0.0.1:8000:8000"
15+
- "127.0.0.1:8001:8001"
16+
- "127.0.0.1:8002:8002"
2117
restart: always
2218

2319
pg-example:
24-
image: postgres:16.1-alpine3.19
20+
image: postgres:17-alpine
2521
container_name: pg-example
2622
environment:
2723
- POSTGRES_USER=marcus
2824
- POSTGRES_PASSWORD=marcus
2925
- POSTGRES_DB=application
3026
volumes:
31-
- ./data/postgres/:/var/lib/postgresql/data
32-
- ./database/structure.sql:/docker-entrypoint-initdb.d/1.sql
33-
- ./database/data.sql:/docker-entrypoint-initdb.d/2.sql
27+
- postgres_data:/var/lib/postgresql/data
3428
ports:
35-
- 127.0.0.1:5432:5432
29+
- "127.0.0.1:5432:5432"
3630
restart: always
3731

3832
redis-example:
39-
image: redis:7-alpine
33+
image: redis:8-alpine
4034
container_name: redis-example
4135
ports:
42-
- 127.0.0.1:6379:6379
36+
- "127.0.0.1:6379:6379"
4337
restart: always
4438

39+
volumes:
40+
postgres_data:
41+
4542
networks:
4643
default:
4744
name: api-example-network

0 commit comments

Comments
 (0)