From 520bd26e0880b38cf2417a922b432b7a979219f9 Mon Sep 17 00:00:00 2001 From: Zenfection Date: Thu, 21 Sep 2023 11:26:01 +0700 Subject: [PATCH] Init Docker Container with postgreSQL and Redis Database --- server/.dockerignore | 4 ++++ server/.env | 3 +++ server/Dockerfile | 20 +++++++++++++++++++ server/docker-compose.yml | 41 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 server/.dockerignore create mode 100644 server/.env create mode 100644 server/Dockerfile create mode 100644 server/docker-compose.yml diff --git a/server/.dockerignore b/server/.dockerignore new file mode 100644 index 0000000..42d24d3 --- /dev/null +++ b/server/.dockerignore @@ -0,0 +1,4 @@ +.vscode/ +node_modules/ +dist/ +npm-debug.log \ No newline at end of file diff --git a/server/.env b/server/.env new file mode 100644 index 0000000..daa5d02 --- /dev/null +++ b/server/.env @@ -0,0 +1,3 @@ +POSTGRES_USER=zenfection +POSTGRES_PASSWORD=123456 +POSTGRES_DB=task-management \ No newline at end of file diff --git a/server/Dockerfile b/server/Dockerfile new file mode 100644 index 0000000..cd73b2b --- /dev/null +++ b/server/Dockerfile @@ -0,0 +1,20 @@ +FROM node:16 AS builder + +WORKDIR /app + +COPY package*.json ./ + +RUN npm install + +COPY . . + +RUN npm run build + +FROM node:16 + +COPY --from=builder /app/node_modules ./node_modules +COPY --from=builder /app/package*.json ./ +COPY --from=builder /app/dist ./dist + +EXPOSE 3000 +CMD [ "npm", "run", "start:prod" ] \ No newline at end of file diff --git a/server/docker-compose.yml b/server/docker-compose.yml new file mode 100644 index 0000000..6e0265a --- /dev/null +++ b/server/docker-compose.yml @@ -0,0 +1,41 @@ +version: '3.8' +services: + task-server: + build: + context: . + dockerfile: Dockerfile + container_name: task-server + restart: always + ports: + - '3000:3000' + depends_on: + - task-server-postgres + - task-server-redis + env_file: + - .env + + task-server-postgres: + image: postgres:latest + container_name: task-server-postgres + restart: always + ports: + - '5432:5432' + env_file: + - .env + volumes: + - task-server-postgres:/var/lib/postgresql/data + + task-server-redis: + image: redis:latest + container_name: task-server-redis + restart: always + ports: + - '6379:6379' + volumes: + - task-server-redis:/var/lib/redis/data + +volumes: + task-server-postgres: + name: postgres-db + task-server-redis: + name: redis-db