Hi ,
I am looking for a help to understand what I’m doing wrong that my Node.js app can not connect to a remote ( non containerized ) POSTGRES DATABASE
My Environment
Database Host : 192.168.0.189
Application Host : 192.168.0.150
My Connection to database is coded like this
const { Pool } = require("pg");
var parse = require('pg-connection-string').parse
var HOST = ''
var DATABASE_URL = ''
const { DB_NAME, DB_USER, DB_PORT, DB_PASS, NODE_ENV } = process.env
console.log(DB_USER)
console.log(NODE_ENV)
if (NODE_ENV == 'development') {
HOST = 'macmini2012.local'
console.log(HOST)
pool = new Pool({
user: DB_USER,
password: DB_PASS,
host: HOST,
database: DB_NAME,
port: DB_PORT
})
When I run my application outside a Container … I can connect to Database and everything works fine .
But I would like to have this app inside a container … defined with this docker-compose.yml
drestoque:
build:
context: .
dockerfile: Dockerfile.dev
ports:
- 3009:3009
env_file:
- config/env/.env
volumes:
- .:/app
Dockerfile.dev is like this
ARG NODE_ENV
FROM node:14.17-slim
WORKDIR /app
COPY package.json /app/package.json
RUN npm install
COPY . /app
EXPOSE 3009
CMD ["npm", "run", "dev"]
When I try to run the app inside the Container … I can not connect to Progres Database
I can connect from inside a test container running the following
Dockerfile
FROM ubuntu
RUN apt-get update
RUN apt-get install -y postgresql-client
ENV PGPASSWORD myPassword
CMD psql --host=<database host ip> --port=5432 --username=postgres -c "SELECT * from drestoque.organization ;"
docker build -t testconn .
docker run --rm testconn:latest
id | name | address | taxid
----+---------------+------------+-------
1 | Organizacao 1 | Endereco 1 | 191
2 | Organizacao 2 | Endereco 2 | 191
3 | Organizacao 3 | Endereco 3 | 191
(3 rows)
Any idea what I am missing ?