Skip to content

Docker Compose fix for MongoDB hostname + build context paths #23

Description

@OmarChouchane

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions