Skip to content

Commit bf4e8cb

Browse files
committed
Set up docker compose for server
1 parent 0853a0b commit bf4e8cb

File tree

6 files changed

+48
-1
lines changed

6 files changed

+48
-1
lines changed

.env.examle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
POSTGRES_USER=
2+
POSTGRES_PASSWORD=
3+
POSTGRES_DB=
4+
DATABASE_URL=
5+
PORT=

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
docker_test_db/
3+
.env

Readme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
### Docker Tutorial
2+
3+
This repository demonstrates how to set up a React JS, Node JS server with a PostgreSQL database server inside docker containers and connect them all together
4+
5+
### Setting up the server

docker-compose.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
services:
2+
postgres:
3+
container_name: database
4+
ports:
5+
- "5431:5432"
6+
image: postgres
7+
environment:
8+
POSTGRES_USER: "${POSTGRES_USER}"
9+
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}"
10+
POSTGRES_DB: "${POSTGRES_DB}"
11+
volumes:
12+
- ./docker_test_db:/var/lib/postgresql/data
13+
server:
14+
container_name: server
15+
build:
16+
context: ./server
17+
dockerfile: Dockerfile
18+
# command: npm start
19+
ports:
20+
- "7999:8000"
21+
environment:
22+
DATABASE_URL: "${DATABASE_URL}"
23+
PORT: "${PORT}"
24+
depends_on:
25+
- postgres

server/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM node:18
2+
WORKDIR /server
3+
COPY package.json ./
4+
COPY package-lock.json ./
5+
COPY . .
6+
RUN npm install
7+
RUN npx prisma generate
8+
CMD ["npm", "start"]

server/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
},
1616
"scripts": {
1717
"dev": "nodemon app.js",
18+
"start": "node app.js",
1819
"test": "echo \"Error: no test specified\" && exit 1"
1920
},
2021
"author": "",
2122
"license": "ISC",
2223
"devDependencies": {
2324
"prisma": "^5.14.0"
2425
}
25-
}
26+
}

0 commit comments

Comments
 (0)