Guides
Intermediate10 min read
Deploy a Next.js App
Containerize your Next.js application and deploy it with a custom domain and automatic TLS.
Step 1: Dockerize your app
Add a Dockerfile to your Next.js project:
Dockerfile
FROM node:20-alpine AS base
WORKDIR /app
FROM base AS deps
COPY package.json pnpm-lock.yaml ./
RUN corepack enable pnpm && pnpm install --frozen-lockfile
FROM base AS builder
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN pnpm build
FROM base AS runner
ENV NODE_ENV=production
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/public ./public
EXPOSE 3000
CMD ["node", "server.js"]Make sure output: 'standalone' is set in your next.config.js.
Step 2: Push to a registry
bash
docker build -t ghcr.io/youruser/myapp:latest .bash
docker push ghcr.io/youruser/myapp:latestStep 3: Create a service in DevPanel
compose.yml
services:
app:
image: ghcr.io/youruser/myapp:latest
ports:
- "3000:3000"
environment:
DATABASE_URL: ${DATABASE_URL}
restart: unless-stoppedAdd DATABASE_URL and any other secrets in the environment variables panel before deploying.
Step 4: Add a custom domain
Go to the service's Domains tab, add your domain (e.g. app.example.com), and select port 3000. DevPanel creates the DNS record and provisions TLS automatically.