-1
Hello
I am studying Docker Compose, I made a simple API to make user CRUD, but I want to climb a container to run the Node and one with postgres and they communicating I did the following 'Docker Compose.yml' :
version: "3.3"
services:
app:
build: .
depends_on:
- db
command: yarn dev
ports:
- "3333:3333"
volumes:
- .:/user/app
links:
- db
db:
image: postgres
restart: always
ports:
- "5433:5432"
volumes:
- /var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: -senha-
POSTGRES_USER: -user-
I left the outer door as the 5433 because I already have another postgres bench running at door 5432
My 'knexfile.js' file looks like this:
// Update with your config settings.
module.exports = {
development: {
client: 'sqlite3',
connection: {
filename: './dev.sqlite3'
}
},
staging: {
client: 'postgresql',
connection: {
database: 'my_db',
user: 'username',
password: 'password'
},
pool: {
min: 2,
max: 10
},
migrations: {
tableName: 'knex_migrations'
}
},
production: {
client: 'postgresql',
connection: {
port: 5433,
database: 'nome banco',
user: 'user',
password: 'senha'
},
pool: {
min: 2,
max: 10
},
migrations: {
tableName: 'knex_migrations'
}
}
};
when I execute the docker-compose up
it creates and performs very well if I try to communicate with the API with Insomnia works, if I try to communicate with the container postgres with Dbeaver works the same, but the API does not communicate with the bank, the error:
{
"errno": -111,
"code": "ECONNREFUSED",
"syscall": "connect",
"address": "127.0.0.1",
"port": 5433
}
What am I doing wrong so they won’t communicate? I’ve searched a lot about it and found nothing.
danizavtz thank you very much for the answer, that was part of the problem, I had actually already installed the
pg
but I wasn’t using it in the knex because I thought it was postgresql kkkk– Geovane
and the other part was the host: I had no idea that I had to put the same name generated in the Compose but I noticed something that the tdvias tmb answered below the door inside the container has to be the 5432 because the one that I set 5433 is the port to access from outside the Docker network
– Geovane