AutoHost logoAutoHost

Command Palette

Search for a command to run...

Tutorials

Deploy a Next.js App

Step-by-step guide to deploy a Next.js application with AutoHost.

This tutorial walks you through deploying a Next.js application to your own infrastructure using AutoHost.

Prerequisites

  • AutoHost CLI installed
  • At least one connected node
  • A Next.js application

Prepare Your App

1

Create a Dockerfile

Add a Dockerfile to your Next.js project:

dockerfile
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM node:20-alpine AS runner
WORKDIR /app
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"]
2

Create autohost.yaml

Define your deployment configuration:

yaml
name: my-nextjs-app
version: "1.0"

services:
  web:
    build: .
    ports:
      - "3000:3000"
    replicas: 2
    health_check:
      path: /api/health
      interval: 30s
    env:
      - NODE_ENV=production

Deploy

bash
autohost deploy

Zero-Downtime Deployments

AutoHost automatically performs rolling deployments, ensuring your application stays available during updates.