Skip to content

Fix MongoDB hostname + build contexts - #24

Open
OmarChouchane wants to merge 8 commits into
iam-veeramalla:composefrom
OmarChouchane:main
Open

Fix MongoDB hostname + build contexts#24
OmarChouchane wants to merge 8 commits into
iam-veeramalla:composefrom
OmarChouchane:main

Conversation

@OmarChouchane

Copy link
Copy Markdown

Short summary:

backend tried to resolve mongodb while service name is mongo.

Changes:

updated MONGODB_URI, compose build contexts, added healthcheck. Fixes #23.

Copilot AI review requested due to automatic review settings February 10, 2026 21:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a critical Docker Compose configuration issue where the backend service attempted to connect to a MongoDB instance with hostname mongodb, but the Docker service was named mongo. The PR also relocates the docker-compose.yaml file from the repository root to the mern/ directory and updates build contexts accordingly.

Changes:

  • Fixed MongoDB hostname from mongodb to mongo in backend connection string
  • Moved docker-compose.yaml to mern/ directory with corrected build contexts
  • Added MongoDB healthcheck and service dependency management
  • Removed outdated GitHub Actions workflow and root-level docker-compose.yaml
  • Added basic README documentation

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
mern/docker-compose.yaml New compose file with correct MongoDB service name, healthcheck, and build contexts relative to mern/ directory
mern/backend/db/connection.js Updated MongoDB URI to use correct hostname 'mongo' with environment variable support
mern/frontend/Dockerfile Removed redundant comments and reformatted
docker-compose.yaml Removed outdated root-level compose file that had incorrect service names and paths
README.md Added basic documentation for running the project locally and with Docker
.github/workflows/main.yaml Removed broken workflow that referenced non-existent directory paths

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread README.md

**Note** - To run this project using `docker compose`, follow the below steps.

Switch to the `compose` branch to learn the

Copilot AI Feb 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README reference to a 'compose' branch and instructions to "Switch to the compose branch to learn" appears incomplete. The sentence on line 5 ends abruptly without completing the thought. Either complete this sentence or remove the reference if the compose branch doesn't exist or isn't relevant.

Suggested change
Switch to the `compose` branch to learn the
Switch to the `compose` branch to learn the following Docker-based setup:

Copilot uses AI. Check for mistakes.
Comment thread mern/docker-compose.yaml
Comment on lines +21 to +22
ports:
- "27017:27017"

Copilot AI Feb 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MongoDB service is exposing port 27017 to the host without authentication configured. This creates a security risk as anyone with network access can connect to the database. Consider either removing the port mapping (services within the same Docker network can communicate without exposing ports to the host) or adding authentication via environment variables like MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD.

Suggested change
ports:
- "27017:27017"

Copilot uses AI. Check for mistakes.
Comment thread README.md
Comment on lines +8 to +9
2. Run the containers using `Docker Compose`.

Copilot AI Feb 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README mentions running the project using 'docker compose' but doesn't provide the actual commands. Since the docker-compose.yaml file is now located in the mern/ directory, users need to know to run 'cd mern && docker compose up' or 'docker compose -f mern/docker-compose.yaml up' from the root directory. Consider adding these instructions to make the documentation complete.

Suggested change
2. Run the containers using `Docker Compose`.
2. Run the containers using `Docker Compose`. From the project root you can either:
- Change into the `mern` directory and run:
```bash
cd mern
docker compose up
```
- Or, from the project root, specify the compose file explicitly:
```bash
docker compose -f mern/docker-compose.yaml up
```

Copilot uses AI. Check for mistakes.
Comment thread mern/docker-compose.yaml
volumes:
- mongo-data:/data/db
healthcheck:
test: ["CMD", "mongosh", "--eval", "db.runCommand({ ping: 1 })"]

Copilot AI Feb 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The healthcheck uses 'mongosh' which is only available in MongoDB 5.0+. While 'mongo:latest' should include this, it would be more robust to add '--quiet' flag to suppress verbose output and use 'mongosh --quiet --eval' to make the healthcheck cleaner. Alternatively, for better compatibility with older MongoDB versions, consider using 'echo "db.runCommand({ ping: 1 })" | mongosh --quiet' or the legacy 'mongo' command.

Suggested change
test: ["CMD", "mongosh", "--eval", "db.runCommand({ ping: 1 })"]
test: ["CMD", "mongosh", "--quiet", "--eval", "db.runCommand({ ping: 1 })"]

Copilot uses AI. Check for mistakes.
Comment thread mern/docker-compose.yaml
ports:
- "5173:5173"
networks:
- mern

Copilot AI Feb 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The frontend environment is missing the backend API URL configuration. When running in Docker, the frontend container cannot reach the backend using 'http://localhost:5050' because each container has its own localhost. The old docker-compose.yaml had 'REACT_APP_API_URL: http://backend:5050' configured. You should either add this environment variable back or update the frontend code to use a configurable backend URL. For Vite, use 'VITE_API_URL' as the environment variable name.

Suggested change
- mern
- mern
environment:
- VITE_API_URL=http://backend:5050

Copilot uses AI. Check for mistakes.
Comment thread README.md
#### Start Server:

```
cd mern/server

Copilot AI Feb 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The directory path 'mern/server' is incorrect. The actual backend directory is 'mern/backend'. This should be updated to 'cd mern/backend' to match the actual project structure.

Suggested change
cd mern/server
cd mern/backend

Copilot uses AI. Check for mistakes.
Comment thread README.md
#### Start Client

```
cd mern/client

Copilot AI Feb 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The directory path 'mern/client' is incorrect. The actual frontend directory is 'mern/frontend'. This should be updated to 'cd mern/frontend' to match the actual project structure.

Suggested change
cd mern/client
cd mern/frontend

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docker Compose fix for MongoDB hostname + build context paths

3 participants