This repository hosts a Dockerized Full-Stack Application built with Node.js, Express, and MongoDB. The project aims to provide a convenient development environment encapsulated within Docker containers. It simplifies the setup and running of a local version of your application.
-
Isolation: Docker containers encapsulate your application and its dependencies, ensuring consistency and preventing conflicts between development and production environments.
-
Portability: Docker containers can run on various platforms without modification, making it easy to move applications between different environments.
-
Efficiency: Docker containers are lightweight and start quickly, reducing resource overhead and speeding up development and deployment processes.
-
Scalability: Docker facilitates the scaling of applications by creating multiple containers from a single image, making it suitable for both small projects and large-scale applications.
-
Dependency Management: Docker enables you to define dependencies and configurations within a Dockerfile, ensuring that your application runs consistently across different environments.
-
Full-Stack Application: This project demonstrates the development of a full-stack web application, including the backend (Node.js) and frontend (EJS templates).
-
Database Integration: MongoDB is used as the database to store application data, and it is containerized using Docker for easy setup.
-
Docker Compose: Docker Compose simplifies multi-container Docker application orchestration, making it effortless to manage both the application and database containers together.
.
├── app
│ ├── Dockerfile
│ ├── index.js
│ ├── models
│ │ └── Item.js
│ ├── node_modules
│ ├── package.json
│ └── views
│ └── index.ejs
├── docker-compose.yml
└── README.md
-
app/
: Contains the Node.js application code.Dockerfile
: Defines the Docker image for the Node.js application.index.js
: Main application file.models/
: Houses application data models.node_modules/
: Holds Node.js dependencies.package.json
: Specifies Node.js application configuration.views/
: Stores application views.
-
docker-compose.yml
: Specifies Docker services and their interactions. -
README.md
: The file you are currently reading.
Note: The
node_modules
directory is intentionally not included in the repository. It is generated locally when you install project dependencies usingnpm install
. This omission keeps the repository size smaller and avoids adding a large number of third-party library files to version control. Thepackage.json
file specifies the project's dependencies, giving you a general idea of what thenode_modules
directory will contain and where to find it.
The docker-compose.yml
file defines two Docker services:
- Dockerizes the Node.js application.
- Exposes port 3000 for accessing the application.
- Links to the
mongo
service for database connectivity. - Mounts the application code and node_modules for development.
- Utilizes the official MongoDB Docker image.
- Exposes port 27017 for MongoDB access.
To set up and run the Dockerized Full-Stack Application:
- Ensure Docker and Docker Compose are installed on your system.
- Clone this repository to your local machine.
- Navigate to the project directory.
cd dockerized-fullstack-application
- Build and start the application using Docker Compose.
docker-compose up --build
- Access the application in your web browser at
http://localhost:3000
. - To shut down the application and clean up Docker resources when you're done:
- Press
Ctrl+C
in the terminal where Docker Compose is running to stop the containers. - To remove the stopped containers, networks, and volumes associated with this project, run:
docker-compose down
- Additionally, you can remove any unused Docker resources (e.g., dangling images, containers, and networks) by running:
docker system prune -a
- These commands will help you gracefully shut down the application and free up any unused Docker resources.
The project relies on the following key dependencies:
- Express: Web framework for Node.js.
- Mongoose: MongoDB object modeling tool.
- EJS: Embedded JavaScript templates.
- Body Parser: Middleware for parsing HTTP request bodies.
Thank you!