This project uses Docker Compose to set up a MongoDB, backend, and frontend service. The services communicate with each other to provide a fully functional application environment.
- Image:
mongodb/mongodb-community-server:latest
- Container Name:
mongodb-database-1
- Restart Policy: Always
- Ports:
27017:27017
- Volume:
mongo_data:/data/db
- Environment Variables:
MONGO_INITDB_DATABASE=mydb
- Build Context:
./backend-service
- Container Name:
backend-service
- Restart Policy: Always
- Depends On:
mongodb
- Ports:
3002:3002
- Environment Variables:
MONGO_URI=mongodb://mongodb:27017/todoapp
PORT=3002
- Build Context:
./frontend-service
- Container Name:
frontend-service
- Restart Policy: Always
- Depends On:
backend
- Ports:
8080:8081
- Environment Variables:
REACT_APP_BACKEND_URL=http://backend:3002
git clone <your-repo-url>
cd <your-repo-name>
To build and run all services in detached mode:
docker-compose up --build -d
Check if all containers are running:
docker ps
To stop and remove containers:
docker-compose down
- The MongoDB service uses a Docker volume (
mongo_data
) to persist database data. - To remove persistent data, delete the volume using:
docker volume rm mongo_data
- Ensure Docker and Docker Compose are installed before running the setup.
- The backend should be fully initialized before frontend requests data.
- If using
init.db.js
, ensure MongoDB is fully ready before executing it manually:docker exec backend-service node init.db.js