Skip to content

Commit

Permalink
update docker local setup
Browse files Browse the repository at this point in the history
  • Loading branch information
milon27 committed Mar 4, 2025
1 parent 27d39d2 commit 8485520
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
5 changes: 3 additions & 2 deletions .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ PORT=4000
TZ=Etc/UTC

# database
DATABASE_URL="mysql://root:myPassWord@localhost:3308/test" # test, test
DATABASE_URL="mysql://root:myPassWord@np_mysql:3308/test"

# redis
# with ssl
# REDIS_URL="rediss://default:[email protected]:6379"
# without ssl
REDIS_URL="redis://default:1234567@localhost:6379"
REDIS_URL="redis://default:1234567@np_redis:6379"
# redis cluster (not used)
REDIS_CLUSTER_ENABLE='false'
REDIS_CLUSTER_URLS="one,two,three"
Expand All @@ -28,6 +28,7 @@ ENABLE_SOCKET='false'
LOKI_HOST="https://xxxxx.grafana.net"
LOKI_AUTH="xxxxxxxxxxxxxxxxxxxxxxxxx"

# todo : mailhog setup here for dev
# SMTP Mail
SMTP_HOST="smtp-relay.xxxx.com"
SMTP_PORT=587
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:20.18.0-alpine as build
FROM node:20.18.0-alpine AS build
RUN npm install -g pnpm

WORKDIR /app
Expand All @@ -14,7 +14,7 @@ RUN npm run build

# # ------------------dev -------------------

FROM node:20.18.0-alpine as dev
FROM node:20.18.0-alpine AS dev
RUN npm install -g pnpm

WORKDIR /app
Expand All @@ -36,7 +36,7 @@ CMD ["/bin/sh", "-c", "pnpm db:migrate:prod && pnpm db:seed:prod && node dist/sr

# # ------------------prod -------------------

FROM node:20.18.0-alpine as prod
FROM node:20.18.0-alpine AS prod
RUN npm install -g pnpm

WORKDIR /app
Expand Down
27 changes: 15 additions & 12 deletions docker-compose.local.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
services:
# mysql:
# container_name: mysql
# image: mysql:8.0.33
# restart: always
# environment:
# - MYSQL_ROOT_PASSWORD=myPassWord
# - MYSQL_DATABASE=test
# ports:
# - 3308:3306
# volumes:
# - db_vol:/var/lib/mysql
np_mysql:
container_name: np_mysql
image: mysql:8.0.33
restart: always
environment:
- MYSQL_ROOT_PASSWORD=myPassWord
- MYSQL_DATABASE=test
ports:
- 3309:3306
networks:
- np_network
volumes:
- db_vol:/var/lib/mysql
# - .backup-db:/docker-entrypoint-initdb.d

np_redis:
Expand All @@ -29,10 +31,11 @@ services:
container_name: np_api
depends_on:
- np_redis
- np_mysql
build:
context: .
dockerfile: Dockerfile
target: prod
target: dev
restart: always
ports:
- 4000:4000
Expand Down
7 changes: 5 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ npx nestpress@latest module category blog
# for more use of nestpress cli checkout this: https://www.npmjs.com/package/nestpress
```

## How to run
## How to run with docker

- make sure you have [docker](https://www.docker.com/products/docker-desktop/) and [pnpm](https://pnpm.io/) install on your system as node package manager
- run mysql database and redis on docker(you should have docker install on your machine)

- run `docker compose up` this will run the database and redis on docker[use git-bash terminal in windows or for mac/linux default terminal is fine]
- run `docker compose -f docker-compose.local.yml up --build` this will run the api server, database and redis on docker[use git-bash terminal in windows or for mac/linux default terminal is fine]
- you can view the server on `http://localhost:4000`

## How to run without docker

- install all dependencies and run the app

Expand Down

0 comments on commit 8485520

Please sign in to comment.