Docker Compose cannot connect to database
Take a look at your /etc/hosts
inside the backend
container. You will see
192.0.18.1 dir_db_1
or something like that. The IP will be different and dir
will represent the dir you're in. Therefore, you must change TYPEORM_HOST=localhost
to TYPEORM_HOST=dir_db_1
.
Although, I suggest you set static names to your containers.
services: db: container_name: project_db ... backend: container_name: project_backend
In this case you can always be sure, that your container will have a static name and you can set TYPEORM_HOST=project_db
and never worry about the name ever again.