I have a node server that's trying to connect to a postgres database using knex. Both are in docker containers with the same custom network. I keep getting ECONNREFUSED errors. I've poked around in the database container and I see that my DB (test_db) has been created by psql but it has no permissions. After giving root permissions, I'm still getting the same issues. I've tried removing the volumes with docker-compose down -v but still no luck. I've also tried removing knex and just using node-postgres but same errors. I'm also unable to connect to the Db from the host using pgadmin. Would appreciate any help!
Here's my docker-compose.yml
version: "3"
services:
server:
build:
context: .
dockerfile: development.Dockerfile
ports:
- "8081:8081"
volumes:
- .:/src
- /src/node_modules
networks:
- dev-network
environment:
DB_HOSTNAME: pg-development
DB_USER: root
DB_PASSWORD: helloworld
DB_PORT: 3306
DB_NAME: test_dev
depends_on:
- pg-development
pg-development:
image: postgres
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: helloworld
POSTGRES_DB: test_dev
ports:
- "3308:3306"
volumes:
- dbdata:/data/db
networks:
- dev-network
healthcheck:
test: ["CMD-SHELL", "pg_isready -U root -d test_dev"]
interval: 10s
timeout: 2s
retries: 10
networks:
dev-network:
driver: bridge
volumes:
dbdata:
Here's my db connection
import knex from "knex";
const connection = {
host: process.env.DB_HOSTNAME,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
port: Number(process.env.DB_PORT),
database: process.env.DB_USER,
};
const db = knex({
client: "pg",
connection,
debug: true,
pool: {
min: 0,
max: 50,
afterCreate: function (conn, done) {
conn.query('SET timezone="UTC";', function (err) {
if (err) {
done(err, conn);
}
});
},
},
});
process.env.DB_HOSTNAME?localhostor docker ip?