A production-ready Next.js template with Docker, PostgreSQL, and automatic deployment to VPS. This template provides a complete setup for developing and deploying Next.js applications.
- 🚀 Next.js 15 with App Router
- 🐳 Docker and Docker Compose setup
- 🐘 PostgreSQL database with Prisma ORM
- 🔒 HTTPS with automatic SSL certification
- 🔄 Development hot reloading
- 🚦 GitHub Actions CI/CD pipeline
- 🌐 Nginx reverse proxy
- Node.js 20+
- Docker and Docker Compose
- Git
- VPS (Recommended: HostMyServers)
- A GitHub account with:
- Access to GitHub Container Registry (GHCR)
- Permission to create repositories and secrets
-
Clone and setup:
git clone https://github.com/yourusername/your-repo-name.git cd your-repo-name cp .env.development.example .env -
Start development environment:
docker compose up --build
-
Open http://localhost:8080 in your browser
The development environment is configured with hot reloading and debugging capabilities:
# Start development containers
docker compose up --build
# Run database migrations
docker compose exec web npx prisma migrate dev
# View logs
docker compose logs -fWe provide two example environment files:
-
.env.development.example- Local development variables# For local development cp .env.development.example .envContains variables for:
- Local database configuration
- Development server settings
- Hot reload configuration
-
.env.production.example- Production deployment variables# For production deployment cp .env.production.example .envContains variables for:
- Production database credentials
- Domain configuration
- SSL certificates
- GitHub Container Registry
- VPS deployment settings
Make sure to:
- Never commit your actual
.envfile - Use strong passwords in production
- Keep your tokens and SSH keys secure
-
Sign up for a VPS at HostMyServers
- French hosting provider with excellent support
- Reliable infrastructure
- Competitive pricing
-
Configure your server:
# Install Docker curl -fsSL https://get.docker.com -o get-docker.sh sudo sh get-docker.sh # Install Docker Compose sudo curl -L "https://github.com/docker/compose/releases/download/v2.23.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose # Install Nginx sudo apt update sudo apt install nginx
-
Set up SSL certificates:
# Install certbot sudo apt install certbot python3-certbot-nginx # Generate certificates sudo certbot --nginx -d yourdomain.com
-
Add these secrets to your GitHub repository:
VPS_HOST: Your VPS IP addressVPS_USERNAME: Your VPS username (usually 'root')VPS_SSH_KEY: Your SSH private keyGHCR_TOKEN: GitHub Container Registry tokenDOCKER_COMPOSE_PROD: Production docker-compose.yml contentNGINX_CONF: Production nginx.conf contentPOSTGRES_USER: PostgreSQL usernamePOSTGRES_PASSWORD: PostgreSQL passwordPOSTGRES_DB: PostgreSQL database name
-
Update the domain in
.github/workflows/deploy.yml:PRODUCTION_DOMAIN: yourdomain.com
-
Update the repository name in the GitHub Container Registry URL:
IMAGE_NAME: ${{ github.repository }}
The deployment process is automated through GitHub Actions:
-
Build and Test
- Build the Next.js application
- Run tests
-
Docker Image
- Build and push to GHCR
-
Database Migration
- Run Prisma migrations
-
Application Deployment
- Deploy services in order:
- PostgreSQL
- Migrations
- Next.js app
- Nginx
- Deploy services in order:
.
├── .github/workflows # GitHub Actions workflows
├── nginx # Nginx configuration
├── prisma # Database schema and migrations
├── src # Application source code
├── docker-compose.yml # Development configuration
├── docker-compose.prod.yml # Production configuration
└── next.config.ts # Next.js configuration
-
Database Connection Issues
- Check PostgreSQL container status
- Verify credentials
- Check logs:
docker-compose -f docker-compose.prod.yml logs db
-
Migration Issues
- Check logs:
docker-compose -f docker-compose.prod.yml logs migrations - Verify DATABASE_URL
- Check logs:
-
Application Issues
- Check logs:
docker-compose -f docker-compose.prod.yml logs web - Verify environment variables
- Check logs:
-
Nginx/SSL Issues
- Check logs:
docker-compose -f docker-compose.prod.yml logs nginx - Verify SSL certificate setup
- Check logs:
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
- Next.js - The React Framework
- Docker - Container Platform
- PostgreSQL - Database
- HostMyServers - VPS Hosting Provider
- Reliable French hosting
- Excellent customer support
- High-performance infrastructure
This project is licensed under the MIT License - see the LICENSE file for details.