Answer the question
In order to leave comments, you need to log in
How to access from the container to the database, which works locally on localhost:5432?
Hello!
I'm trying to connect from a container to a database that works locally at localhost:5432, but the database is not visible from the container.
//docker-compose
version: "3"
services:
server:
image: node:latest
command: sh -c "npm install && npm run dev"
volumes:
- ./backend:/usr/src/client
working_dir: /usr/src/client
ports:
- "9001:9001"
restart: always
tty: true
//пытаюсь подключиться к локальной базе
const { Pool } = require('pg');
const pool = new Pool({
host: '127.0.0.1',
user: 'andrejkolosov',
password: 'ipadib339',
port: 5432,
database: 'docker'
});
module.exports = pool
//в итоге такая ошибка
node:internal/process/promises:246
server_1 | triggerUncaughtException(err, true /* fromPromise */);
server_1 | ^
server_1 |
server_1 | Error: connect ECONNREFUSED 127.0.0.1:5432
server_1 | at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1133:16) {
server_1 | errno: -111,
server_1 | code: 'ECONNREFUSED',
server_1 | syscall: 'connect',
server_1 | address: '127.0.0.1',
server_1 | port: 5432
server_1 | }
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question