I got the project, I try the game and it gives out:
ERROR [TypeOrmModule] Unable to connect to the database. Retrying (2)...
error: ������������ "admin" �� ������ �������� ����������� (�� ������)
at Parser.parseErrorMessage (E:ProgrammingNodejsLandProsportmastersportmaster_bitbucketnode_modulespg-protocolsrcparser.ts:369:69)
The project has a container defined in docker-compose.yml, but the application itself is local – not in docker
-
I run docker-compose up -d
the container is created, I look at the necessary database is created -
I launch the nest start application and the error is – it cannot connect to the database
docker-compose.yml:
version: '3.8' services: db: container_name: sportmaster image: postgres:14.4 restart: always environment: - POSTGRES_USER=${TYPEORM_USERNAME} - POSTGRES_PASSWORD=${TYPEORM_PASSWORD} - POSTGRES_DB=${TYPEORM_DATABASE} volumes: - ./pgdata:/var/lib/postgresql/data ports: - ${TYPEORM_PORT}:${TYPEORM_PORT}
.env:
TYPEORM_USERNAME=admin
TYPEORM_PASSWORD=admin
TYPEORM_DATABASE=sportmasterDB
TYPEORM_PORT=5432
typeOrm config:
const ormconfig: TypeOrmModuleOptions = {
type: 'postgres',
username: process.env.TYPEORM_USERNAME,
password: process.env.TYPEORM_PASSWORD,
database: process.env.TYPEORM_DATABASE,
host: 'localhost',
port: 5432,
logging: false,
entities: [
Order,
],
synchronize: true,
autoLoadEntities: true,
};
export default ormconfig;
docker-compose ps:
Name Command State Ports
sportmaster docker-entrypoint.sh postgres Up 0.0.0.0:5432->5432/tcp
2
Answers
You need to provide "host" in your database settings.
Try this:
The host is a docker-compose database service name.
You can add this variable in your ".env" file.
.env:
typeOrm config:
I’ve faced the same problem recently. In my case it was caused by
postgres service
running on Windows and listening to the same port. Apparently, I installed it some time ago and completely forgot. I’m almost sure you have the same problem. Just try to stop thepostgres service
.In order to stop Windows service press
Win+R
, then typeservices.msc
, hit enter, find posgress service, stop it. You can also change it’s startup type tomanual
to prevent it from starting at boot.