Overview
Some users hit MongoServerSelectionError: getaddrinfo EAI_AGAIN mongodb when starting the backend container.
This happens because the MongoDB service name in docker-compose is mongo, but the backend tries to connect to mongodb.
Also, the compose file lives in mern/ but uses build paths like mern/frontend, which break when running from repo root.
Symptoms
Backend logs show: MongoServerSelectionError: getaddrinfo EAI_AGAIN mongodb
Root Cause
Docker DNS resolves service names, not arbitrary hostnames.
Build context paths are incorrect relative to the compose file location.
Fix
Use the correct MongoDB hostname:
mongodb://mongo:27017
or set MONGODB_URI=mongodb://mongo:27017
Add a MongoDB healthcheck and make backend wait:
depends_on with condition: service_healthy
Update build contexts to be relative to docker-compose.yaml:
frontend: build: ./frontend
backend: build: ./backend
Result
Backend connects successfully and the compose build works from repo root.
Overview
Some users hit MongoServerSelectionError: getaddrinfo EAI_AGAIN mongodb when starting the backend container.
This happens because the MongoDB service name in docker-compose is mongo, but the backend tries to connect to mongodb.
Also, the compose file lives in mern/ but uses build paths like mern/frontend, which break when running from repo root.
Symptoms
Backend logs show: MongoServerSelectionError: getaddrinfo EAI_AGAIN mongodb
Root Cause
Docker DNS resolves service names, not arbitrary hostnames.
Build context paths are incorrect relative to the compose file location.
Fix
Use the correct MongoDB hostname:
mongodb://mongo:27017
or set MONGODB_URI=mongodb://mongo:27017
Add a MongoDB healthcheck and make backend wait:
depends_on with condition: service_healthy
Update build contexts to be relative to docker-compose.yaml:
frontend: build: ./frontend
backend: build: ./backend
Result
Backend connects successfully and the compose build works from repo root.