Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
bezkoder-app/.env
43 changes: 41 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Docker Compose Nodejs and Postgres example

## Run the System
## How to run

### Run the System
We can easily run the whole with only a single command:
```bash
docker compose up
Expand All @@ -13,7 +15,7 @@ The services can be run on the background with command:
docker compose up -d
```

## Stop the System
### Stop the System
Stopping all the running containers is also simple with a single command:
```bash
docker compose down
Expand All @@ -24,6 +26,43 @@ If you need to stop and remove all containers, networks, and all images used by
docker compose down --rmi all
```

## Developing locally
If you want to only run the postgres container run:
```bash
docker compose up postgresdb -d
```

Then you can run the application using [nodemon](https://www.npmjs.com/package/nodemon). This allows you to devop in the application and it will automatically restart when you save a file.

To add the config for the applciation, create a `.env` file inside the `bezkoder-app` folder with the following contents:

```ini
DB_HOST=localhost
DB_USER=postgres
DB_PASSWORD=123456
DB_NAME=bezkoder_db
DB_PORT=5433

NODE_DOCKER_PORT=8080
```

Note this has the same keys as the `.env.sample` file and the same values as the `.env` file from the root of the repo.

To run the application, first navigate to the application folder where `package.json` resides. e.g.

```bash
cd bezkoder-app
```

Then download the dependencies and run the application locally (provided [nodeJS](https://nodejs.org/en/download) is installed):

```bash
npm install
npm run dev
```

## Additional resources

For more detail, please visit:
> [Docker Compose Node.js and Postgres example](https://www.bezkoder.com/docker-compose-nodejs-postgres/)

Expand Down
1 change: 1 addition & 0 deletions bezkoder-app/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
4 changes: 2 additions & 2 deletions bezkoder-app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM node:14
FROM node:20-alpine

WORKDIR /bezkoder-app
COPY package.json .
RUN npm install
COPY . .
CMD npm start
CMD npm start
1 change: 1 addition & 0 deletions bezkoder-app/app/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const dbConfig = require("../config/db.config.js");
const Sequelize = require("sequelize");
const sequelize = new Sequelize(dbConfig.DB, dbConfig.USER, dbConfig.PASSWORD, {
host: dbConfig.HOST,
port: dbConfig.port,
dialect: dbConfig.dialect,

pool: {
Expand Down
Loading