Next.js
Step-by-step guide to deploy a Next.js application on Out Plane
This guide walks you through deploying a Next.js application on Out Plane using Git-driven deployment with a Dockerfile.
Prerequisites
- An Out Plane account
- A GitHub account
- Node.js 18+ installed on your machine
- Git installed on your machine
Create the Next.js App
Create a new Next.js project:
npx create-next-app@latest my-nextjs-app
cd my-nextjs-appWhen prompted, select your preferred options. This guide works with both App Router and Pages Router.
Configure for Production
Open next.config.js (or next.config.mjs) and enable standalone output:
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'standalone',
};
module.exports = nextConfig;The standalone output is required for containerized deployments. It creates a minimal production build with only the necessary files.
Create the Dockerfile
Create a file called Dockerfile in your project root:
FROM node:20-alpine AS deps
WORKDIR /app
COPY package*.json ./
RUN npm ci
FROM node:20-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build
FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
EXPOSE 3000
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
CMD ["node", "server.js"]Create a .dockerignore file:
node_modules
.next
.git
.env*
*.md
.DS_StoreTest Locally
Run the development server to verify your app works:
npm run devOpen http://localhost:3000 in your browser.
To test the production build:
npm run build
npm startPush to GitHub
Initialize a Git repository and push to GitHub:
git init
git add .
git commit -m "Initial commit"
git remote add origin [email protected]:YOUR_USERNAME/my-nextjs-app.git
git branch -M main
git push -u origin mainReplace YOUR_USERNAME with your GitHub username.
Deploy on Out Plane
Step 1: Install GitHub App
- Go to console.outplane.com
- Navigate to Applications from the sidebar
- Click Deploy Application
- If prompted, click Install GitHub App
- Select which repositories Out Plane can access
- Click Install and you'll be redirected back
Step 2: Select Repository
- Find your repository in the list
- Click to select it
- Choose the branch to deploy (default:
main) - Set Root Directory to
/
Step 3: Configure Build
| Setting | Value |
|---|---|
| Build Method | Select Dockerfile |
| Application Name | Enter a unique name (e.g., my-nextjs-app) |
| Port | 3000 |
Step 4: Select Resources
Next.js apps typically need more memory for building. Choose an appropriate instance:
| Instance | vCPU | RAM | Recommended For |
|---|---|---|---|
| op-46 | 1 | 1 GB | Small sites |
| op-82 | 2 | 2 GB | Medium traffic (recommended) |
| op-94 | 4 | 4 GB | High traffic, SSR-heavy |
Step 5: Configure Scaling
- Min Scale: Set to
1for always-on (recommended for SSR) - Max Scale: Set based on expected traffic
Step 6: Environment Variables
Click Add Variable to add environment variables:
| Key | Value |
|---|---|
NODE_ENV | production |
For client-side variables, use the NEXT_PUBLIC_ prefix:
| Key | Value |
|---|---|
NEXT_PUBLIC_API_URL | https://api.example.com |
Variables with NEXT_PUBLIC_ prefix are embedded at build time. Update them requires a new deployment.
Step 7: Deploy
- Review your configuration
- Click Create Application
- Wait for the build to complete (typically 3-5 minutes for Next.js)
Step 8: Access Your App
Once the deployment status shows Ready:
- Go to the application Overview tab
- Find your domain:
my-nextjs-app.outplane.app - Click to open your live application
Automatic Deployments
Push to your branch to trigger automatic deployments:
git add .
git commit -m "Add new feature"
git push origin mainDatabase Connection
To connect to a PostgreSQL database, add the connection string as an environment variable:
- Create a database in the Databases section
- Copy the connection string
- Add it as
DATABASE_URLin your app's environment variables
Example with Prisma:
// lib/prisma.ts
import { PrismaClient } from '@prisma/client';
const globalForPrisma = globalThis as unknown as { prisma: PrismaClient };
export const prisma = globalForPrisma.prisma ?? new PrismaClient();
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma;Troubleshooting
Build fails with memory error
If your build fails with a memory error, add this environment variable:
| Key | Value |
|---|---|
NODE_OPTIONS | --max-old-space-size=4096 |
Or select a larger instance type.
Static files not loading
Ensure your Dockerfile copies both standalone and static directories correctly.