I am a beginner in node, nest, and docker but somehow I got assigned a job to dockerized all the existing node js applications.
Github Repository of this project
Thank you for helping in advance :)
CodePudding user response:
Your problem for a typo in DATABASE_URL
. In code for connect database use DATABSE_URL
word but in docker-compose used DATABASE_URL
.
You should change url: process.env.DATABSE_URL
to url: process.env.DATABASE_URL
CodePudding user response:
Make sure your connection string is correct in your docker-compose.yml
. Just pass the host, port, user and pass seperated and let TypeOrm
handle the connection.
// app.module.ts
TypeOrmModule.forRoot({
type: 'postgres',
host: process.env.POSTGRES_HOST,
port: process.env.POSTGRES_PORT,
username: process.env.POSTGRES_USER,
password: process.env.POSTGRES_PASSWORD,
database: process.env.POSTGRES_DB,
})
And your docker-compose.yml:
# docker-compose.yml
version: '3.9'
services:
api:
build:
dockerfile: Dockerfile
context: .
depends_on:
- postgres
environment:
- POSTGRES_HOST=postgres
- POSTGRES_PASSWORD=promo-pass
- POSTGRES_USER=promo-user
- POSTGRES_DB=promo-api-db
- POSTGRES_PORT=5432
postgres:
container_name: postgres
image: postgres
environment:
POSTGRES_USER: promo-user
POSTGRES_PASSWORD: promo-pass
POSTGRES_DB: promo-api-db