MongoDB on with Docker “failed to connect to server [localhost:27017] on first connect “

By default Compose sets up a single network for your app. Each
container for a service joins the default network and is both
reachable by other containers on that network, and discoverable by
them at a hostname identical to the container name.

According to your docker-compose.yaml file you can access you mongo container on only from host machine.
In order to access it from NodeJS backend container you should use db:27017.

Leave a Comment