A simple RESTful API built with Node.js, Express, and MongoDB, containerized using Docker and orchestrated with Docker Compose.
The project demonstrates how to package an application and its dependencies into isolated containers, providing a consistent development environment and simplifying deployment workflows.
The application consists of two services:
- Express API Container – Runs the Node.js application.
- MongoDB Container – Provides persistent data storage.
Both services communicate through an isolated Docker network and are managed using Docker Compose.
Client
│
▼
┌─────────────────┐
│ Express API │
│ (Container) │
└────────┬────────┘
│
│ Docker Network
│
┌────────▼────────┐
│ MongoDB │
│ (Container) │
└─────────────────┘
- Dockerized Node.js and Express application
- MongoDB running in a separate container
- Multi-container orchestration with Docker Compose
- Environment-based configuration using
.env - Persistent MongoDB storage using Docker volumes
- Container-to-container communication through Docker networking
- Development-friendly setup with bind mounts and automatic reloads
- JWT-based authentication
Docker provides several advantages:
- Consistency – The application runs the same way across different environments.
- Isolation – Dependencies are encapsulated inside containers.
- Portability – The entire stack can run on any machine with Docker installed.
- Reproducibility – Team members can start the project with a single command.
- Scalability – Services can be extended and orchestrated more easily.
Before running the application, make sure you have:
- Docker
- Docker Compose
git clone https://github.com/YousseifNady/dockerized-express-api.git
cd dockerized-express-apiCreate a .env file in the project root:
PORT=3000
# MongoDB
DB_USER=admin
DB_PASSWORD=admin123
DB_DATABASE=appdb
DB_HOST=mongo
DB_PORT=27017
DB_URL=mongodb://admin:admin123@mongo:27017/appdb?authSource=admin
JWT_SECRET_KEY=12345testNote: The application will not start correctly without these environment variables. Docker Compose uses them to configure both the Express application and the MongoDB container.
docker compose up --buildThe API will be available at:
http://localhost:3000
MongoDB will be available at:
mongodb://localhost:27017
docker compose downRemove containers and volumes:
docker compose down -vAPI endpoints, request payloads, and response examples are documented in:
API.md
This documentation includes:
- Authentication endpoints
- User management APIs
- Request and response examples
- Required headers and payloads
.
├── app/
├── index.js
├── Dockerfile
├── docker-compose.yml
├── package.json
├── API.md
├── .env
└── README.md
This project demonstrates practical usage of:
- Docker Images
- Docker Containers
- Docker Networks
- Docker Volumes
- Bind Mounts
- Environment Variables
- Docker Compose
- Multi-service applications
- Containerized development workflows
- JWT Authentication
The credentials and secrets provided in the example .env file are intended for local development only. Use secure passwords and secrets in production environments.
This project is intended for learning purposes and demonstrates how to containerize a Node.js and MongoDB application using Docker and Docker Compose.