A modern, containerized full-stack application built with Docker, Node.js, Next.js, and MySQL. This project demonstrates best practices for building and deploying microservices using Docker containers.
- Features
- Tech Stack
- Project Structure
- Prerequisites
- Installation
- Usage
- API Endpoints
- Docker Configuration
- Environment Variables
- Development
- Production Deployment
- Troubleshooting
- Contributing
- License
- π³ Fully Dockerized - All services run in isolated containers
- π User Management - Complete CRUD operations for user data
- π¨ Modern UI - Beautiful, responsive interface with Tailwind CSS
- π Secure - Non-root users, environment variables, and best practices
- π Auto-reconnect - Database connection with retry logic
- π¦ Microservices Architecture - Separate frontend, backend, and database services
- β‘ Hot Reload - Development mode with instant updates
- Next.js 15 - React framework with TypeScript
- Tailwind CSS - Utility-first CSS framework
- React Hooks - State management with useState and useEffect
- Node.js - JavaScript runtime
- Express.js - Web application framework
- MySQL2 - MySQL database driver
- CORS - Cross-Origin Resource Sharing support
- dotenv - Environment variable management
- MySQL 8.0 - Relational database
- Docker - Containerization platform
- Docker Compose - Multi-container orchestration
fullstackapp/
βββ backend/
β βββ index.js # Express server with API routes
β βββ package.json # Backend dependencies
β βββ Dockerfile # Backend container configuration
β βββ .dockerignore # Files to exclude from Docker build
βββ frontend/
β βββ app/
β β βββ page.tsx # Main UI component
β β βββ layout.tsx # Root layout
β β βββ globals.css # Global styles
β βββ package.json # Frontend dependencies
β βββ Dockerfile # Frontend container configuration
β βββ .dockerignore # Files to exclude from Docker build
β βββ next.config.ts # Next.js configuration
β βββ tsconfig.json # TypeScript configuration
βββ docker-compose.yml # Multi-container orchestration
βββ README.md # Project documentation
Before running this application, make sure you have the following installed:
- Docker Desktop (version 20.10 or higher)
- Docker Compose (version 2.0 or higher)
- Git (for cloning the repository)
docker --version
docker-compose --version- Clone the repository
git clone https://github.com/codezelaca/microservise-docker-app.git
cd microservise-docker-app- Start the application
docker-compose up --buildThis will:
- Pull the MySQL 8.0 image (first time only)
- Build the frontend and backend Docker images
- Start all three containers
- Set up the database with the users table
- Access the application
- Frontend: http://localhost:3000
- Backend API: http://localhost:5000
- MySQL Database: localhost:3307
- Navigate to http://localhost:3000
- Fill in the "Name" and "Email" fields
- Click "Add User"
- The user will appear in the list below
- Find the user in the list
- Click the "Delete" button
- The user will be removed from the database
GET /api/healthReturns the backend service status.
GET /api/usersReturns a list of all users.
Response:
[
{
"id": 1,
"name": "John Doe",
"email": "john@example.com",
"created_at": "2026-03-01T12:00:00.000Z"
}
]POST /api/users
Content-Type: application/json
{
"name": "John Doe",
"email": "john@example.com"
}Response:
{
"id": 1,
"name": "John Doe",
"email": "john@example.com"
}DELETE /api/users/:idResponse:
{
"message": "User deleted"
}- Image: mysql:8.0
- Port: 3307:3306
- Environment:
- MYSQL_ROOT_PASSWORD=rootpassword
- MYSQL_DATABASE=myapp
- Volume: Persistent data storage
- Build: ./backend
- Port: 5000:5000
- Dependencies: Waits for database to be healthy
- Features:
- Database retry logic (10 attempts)
- Automatic table creation
- Non-root user for security
- Build: ./frontend
- Port: 3000:3000
- Dependencies: Waits for backend to start
- Features:
- Hot reload in development
- Non-root user for security
β Alpine Linux base images - Smaller image sizes β Multi-stage optimization - Layer caching with package*.json β npm ci - Faster, more reliable installations β Cache cleaning - Reduced image sizes β Non-root users - Enhanced security β .dockerignore - Exclude unnecessary files β Health checks - Ensure services are ready β Dependency management - Proper service startup order
DB_HOST=database
DB_USER=root
DB_PASSWORD=rootpassword
DB_NAME=myapp
PORT=5000NEXT_PUBLIC_API_URL=http://localhost:5000docker-compose updocker-compose up --builddocker-compose down# All services
docker-compose logs
# Specific service
docker-compose logs backend
docker-compose logs frontend
docker-compose logs database# Backend
docker exec -it fullstack_backend sh
# Frontend
docker exec -it fullstack_frontend sh
# Database
docker exec -it fullstack_mysql mysql -uroot -prootpassword myappcd backend
npm install
# Make sure MySQL is running locally
node index.jscd frontend
npm install
npm run devFor production, consider these modifications:
- Use production builds
RUN npm run build
CMD ["npm", "start"]- Use secrets for passwords
secrets:
db_password:
external: true-
Add nginx reverse proxy
-
Enable SSL/TLS certificates
-
Set up proper logging
-
Configure resource limits
Problem: Port 3306 already in use
Error: ports are not available: exposing port TCP 0.0.0.0:3306
Solution: The docker-compose.yml already uses port 3307 to avoid conflicts with local MySQL.
Problem: Frontend can't create .next directory
Error: EACCES: permission denied, mkdir '/app/.next/dev'
Solution: Already fixed with chown -R nextjs:nodejs /app in Dockerfile.
Problem: Backend cannot connect to database
Solution: Wait for the database to be healthy. The backend has retry logic (10 attempts with 5-second delays).
Problem: Frontend shows "Failed to fetch"
Solution: Ensure backend is running and accessible at http://localhost:5000
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
codezelaca
- GitHub: @codezelaca
- Repository: microservise-docker-app
- Docker for containerization
- Next.js team for the amazing framework
- Express.js community
- MySQL for the reliable database
β If you found this project helpful, please give it a star!
π Found a bug? Open an issue