i have this Dockerfile :
FROM node:12
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
CMD [ "npm", "start"]
and docker-compose.yml looks like that :
version: '3.1'
services:
db:
image: postgres
restart: always
volumes:
- ./db-data:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: root
ports:
- 5432:5432
node:
build: .
volumes:
- ./public/storage/files:/usr/app/public/storage/files
env_file: .env
restart: always
ports:
- '8080:8080'
When projects starts it uses ormconfig.json
{
"type": "postgres",
"host": "localhost",
"port": 5432,
"username": "postgres",
"database": "postgres",
"password": "root",
"synchronize": true,
"logging": true,
"entities": ["dist/**/*.entity.js"]
}
But i have error when run it in docker
[Nest] 30 - 08/19/2020, 5:49:39 PM [TypeOrmModule] Unable to connect to the database. Retrying (4)... +3003ms
node_1 | Error: connect ECONNREFUSED 127.0.0.1:5432
Help pls to fix it. Without docker it works perfectly.