A complete Full Stack application containerized with Docker, featuring a React frontend, Node.js/Express backend, and MongoDB database.
This project demonstrates how to dockerize a dummy full-stack application using Docker Compose. It sets up three containerized services:
- Client: A React application built with Vite.
- Server: A Node.js Express REST API.
- Database: A MongoDB instance.
This project utilizes multi-stage Docker builds to optimize images for different environments. This allows flexibility in building the application for either development (with hot-reloading) or production (optimized static assets).
By default, the docker-compose.yml is configured for the production build. If you wish to build for development or production, you simply need to change the target value in the docker-compose.yml file:
- Production: Set
target: build(serves optimized build on port4173). - Development: Set
target: dev(runs dev server with hot-reloading on port5173).
- Frontend: React, Vite, React Toastify
- Backend: Node.js, Express, Mongoose
- Database: MongoDB
- DevOps: Docker, Docker Compose
Before you begin, ensure you have the following installed on your machine:
Follow these steps to get the application running locally using Docker.
git clone <repository-url>
cd docker-practise-with-fullstack-appBuild and start all services with a single command:
docker-compose up --buildThis command will:
- Build the frontend and backend images.
- Start the MongoDB container.
- Connect the services together on a shared network.
Once the application is running, you can access the services at the following URLs:
| Service | URL | Description |
|---|---|---|
| Frontend | http://localhost:4173 | Main application interface (Production Preview) |
| Backend API | http://localhost:4000 | Backend REST API |
| MongoDB | localhost:27017 |
Database connection |
Note: The frontend is built and served using
vite previewon port 4173 as defined in thedocker-compose.yml(target: build).
To stop the containers and remove the networks, press Ctrl+C in your terminal or run:
docker-compose down