Skip to content

Commit a9d02ea

Browse files
committed
Postgres docker-compose
1 parent be6a749 commit a9d02ea

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

.env.example

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
PORT=5000
2+
3+
# Database configuration
4+
DATABASE_HOST=postgres
5+
DATABASE_NAME=postgresdb
6+
DATABASE_USER=admin
7+
DATABASE_PASSWORD=password123
8+
DATABASE_PORT=5432
9+
DATABASE_URL=postgresql://admin:password123@localhost:5432/postgresdb?schema=public

README.md

+80
Original file line numberDiff line numberDiff line change
@@ -1 +1,81 @@
11
# typescript-fastify-auth-microservice
2+
3+
## Prerequisites installation
4+
5+
### Init
6+
7+
```bash
8+
npm init -y
9+
npx tsc --init
10+
```
11+
12+
### Dependencies
13+
14+
```
15+
npm install fastify fastify-zod zod zod-to-json-schema fastify-swagger fastify-jwt @prisma/client
16+
```
17+
18+
### Dev Dependencies
19+
20+
```
21+
npm install -D ts-node ts-node-dev typescript @types/node dotenv nodemon
22+
```
23+
24+
### Prisma Initialization
25+
26+
```
27+
npx prisma init --datasource-provider postgresql
28+
```
29+
30+
### Prisma db Migration
31+
32+
```
33+
npx prisma migrate dev --name init
34+
```
35+
36+
## Run docker locally
37+
38+
To run database directly inside container, please follow below steps:
39+
40+
- Download docker
41+
42+
- [Windows](https://docs.docker.com/desktop/install/windows-install/)
43+
- [Ubuntu](https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository)
44+
45+
- To change environment variables, please use [.env](.env.example) file
46+
47+
- Run docker container
48+
49+
```bash
50+
npm run start:docker
51+
```
52+
53+
- To stop docker container
54+
55+
```bash
56+
ctrl c
57+
OR
58+
docker-compose down
59+
60+
# To stop with data/volumne cleanup
61+
docker-compose down -v --rmi all
62+
```
63+
64+
- To see containers logs
65+
66+
```bash
67+
docker-compose logs postgres
68+
```
69+
70+
- To connect to Postgres database manually
71+
72+
```bash
73+
docker exec -it postgres bash
74+
psql -U admin -d postgresdb
75+
```
76+
77+
- To see all tables in database
78+
79+
```bash
80+
\dt;
81+
```

docker-compose.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: '3.9'
2+
services:
3+
postgres:
4+
image: postgres:latest
5+
container_name: postgres
6+
environment:
7+
POSTGRES_DB: ${DATABASE_NAME}
8+
POSTGRES_USER: ${DATABASE_USER}
9+
POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
10+
ports:
11+
- ${DATABASE_PORT}:${DATABASE_PORT}
12+
restart: always
13+
volumes:
14+
- postgresdb-data:/var/lib/postgresql/data
15+
16+
volumes:
17+
postgresdb-data:

0 commit comments

Comments
 (0)