Relevant part of the docker-compose.yaml:
version: "3.5"
services:
Database:
image: postgres
container_name: Example-Local-Database
ports:
- "${DATABASE_PORT}:${DATABASE_PORT}"
environment:
- "POSTGRES_PASSWORD=${DATABASE_PASSWORD}"
volumes:
- DatabaseData:/var/lib/postgresql/data
# ...
volumes:
DatabaseData:
name: Example-Local-DatabaseData
driver: local
ENV variables (calm down, no sensitive information to steal, just default settings for the local development mode):
DATABASE_PORT=5432
DATABASE_PASSWORD=pass1234
DataSource configuration:
{
type: "postgres",
host: "Database",
port: 5432,
username: "postgres",
password: "pass1234",
entities: [ MemberModel ]
}
The connection from IntelliJ IDEA is fine:
Same for my NestJS application.
However, the typeorm
CLI could not connect with this database.
For example, the command typeorm migration:generate test/test2 -- -d typeorm-cli.config.ts
causes the error:
Error during migration generation:
Error: getaddrinfo ENOTFOUND Database
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:107:26) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'Database'
}
I have checked the trying to connect typeorm with mysql container in docker-compose but i get this error Error: getaddrinfo EAI_AGAIN mysql topics: in my case, the host refers to Database the service name mentioned in docker-compose.yaml.