Quick Start: Hello World
You can try deploying a minimal Next.js app to test the workflow.- Create a new Next.js app:
- Replace the default page (app/page.tsx for App Router or pages/index.js for Pages Router) with:
- Start locally to verify:
- Commit and push to GitHub/Git provider.
- Deploy on DCDeploy using the steps in the guide below.
Overview
Next.js is a React framework that supports both static and server-rendered applications.On DCDeploy, you can deploy Next.js using:
- Node.js server mode (
next start) for server-side rendering (SSR), API routes, etc. - Docker-based deployment for custom control.
- Static export for static sites (no server-side features).
When to Use Each Mode
| Mode | Use Cases | Limitations |
|---|---|---|
| Node.js Server | Full Next.js features: SSR, API Routes, Middleware, Image Optimization. | Requires more resources; cold-start delay can be higher. |
| Docker Deployment | Custom setup, dependencies, versions. | More complex configuration; build times may increase. |
| Static Export | Blogs, marketing sites, documentation with mostly static content. | No SSR or API routes; dynamic features not supported. |
Prerequisites
- Next.js project with either App Router or Pages Router.
package.jsonscripts:- If using Docker, a Dockerfile in your project root.
- GitHub (or other Git) repository to push your project.
Step-by-Step Guide
- Prepare Your Next.js App
- Choose router type (App Router or Pages Router).
- Ensure dependencies are in package.json.
- If using image optimization (next/image), ensure relevant libs like sharp may be installed.
- Add Dockerfile (optional but recommended for control)
Dockerfile:
- Push Code to Git
- Initialize Git, commit all files, push to your git provider (GitHub, etc.).
- Include .dockerignore to speed up builds when using Docker.
- Deploy on DCDeploy
- In DCDeploy dashboard β Deploy tab in your target environment.
- Create a new service β select Docker Registry / Build from Code.
- Provide image or repo + branch.
- Set port to 3000 (common for Next.js) and ensure app listens on 0.0.0.0.
- Select protocol (http / https) and region(s).
- Choose machine type (CPU, RAM) especially if SSR or many API routes.
- Configure environment variables (NEXT_PUBLIC_*, database URLs, etc.).
- Set minScale / maxScale. If your app is dormant at times, you can allow scaleβtoβzero if enabled.
- Deploy and monitor build + deploy logs.
Static Export Example
If using static export:- Run next export or configure Next.js to export static.
- Serve from static hosting or minimal server.
- Dockerfile might look like:
Best Practices
- Use internal networking for connecting your Next.js app to databases / APIs within DCDeploy instead of making those publicly exposed.
- Enable SSL / custom domain for production.
- Monitor resource usage (CPU, memory), especially if using SSR or Server Components.
- Use caching / ISR (Incremental Static Regeneration) wisely for performance.
- Optimize image sizes and bundle sizes.
Troubleshooting
| Problem | Likely Cause | Solution |
|---|---|---|
| Page showing blank or canβt access | App not listening on 0.0.0.0 or wrong port | Verify listen("0.0.0.0", port) and port match manifest. |
| Image optimization failing | Missing sharp or unsupported library | Install needed libs, ensure docker image includes them. |
| Build timeout / too slow | Large dependencies, cached layers not used | Use slim base image, optimize dependencies, use caching. |
| SSR / API route error on deploy | Environment variables missing or misconfigured | Check env var settings, check logs for stack trace. |
