LogoNEXTDEVKIT Docs

Container

Deploy NEXTDEVKIT using Docker containers to various cloud platforms

Deploy your NEXTDEVKIT application using Docker containers to various cloud platforms for maximum flexibility and control.

🌟 Why Choose Container Deployment?

Container deployment is ideal for applications requiring:

  • 🔧 Full Control: Complete control over runtime environment and dependencies
  • 🌐 Platform Flexibility: Deploy to any cloud provider or on-premises
  • 📦 Consistent Environment: Same environment across development, staging, and production
  • 🔄 Easy Scaling: Horizontal scaling with orchestration platforms
  • 🛡️ Isolation: Process and resource isolation for security
  • ⚡ Fast Deployment: Quick rollouts and rollbacks

🚀 Deployment Steps

Step 1: Configure Environment Variables

Please refer to the Environment Guide for the detailed environment variables.

Copy .env.example to .env.production or .env and update the environment variables.

Step 2: Use Dockerfile

Use the Dockerfile in your project root:

# Use the official Node.js runtime as base image
FROM node:20-alpine AS base

# Install dependencies only when needed
FROM base AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app

# Install dependencies based on the preferred package manager
COPY package.json pnpm-lock.yaml* ./
COPY source.config.ts ./
COPY src/content ./src/content
RUN corepack enable pnpm && pnpm i --frozen-lockfile

# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

# Build the application
RUN corepack enable pnpm && pnpm run build

# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app

ENV NODE_ENV production

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

# Copy the built application
COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 3000

ENV PORT 3000
ENV HOSTNAME "0.0.0.0"

# Start the application
CMD ["node", "server.js"]

Update the next.config.ts file to enable standalone output:

import type { NextConfig } from "next";

const nextConfig: NextConfig = {
  output: "standalone",
};

export default nextConfig;

Step 3: Build and Test Locally

# Build the Docker image
docker build -t nextdevkit:latest .

# Run the container locally
docker run -p 3000:3000 --env-file .env nextdevkit:latest

Step 4: Deploy to Cloud Platform

Choose your preferred cloud platform:

For universal container deployment, NEXTDEVKIT supports all major cloud providers:

PlatformTypeWebsite
Azure Container AppsMicrosoft Cloudazure.microsoft.com
Google Cloud RunGoogle Cloudcloud.google.com
RailwayDeveloper-friendlyrailway.app
Fly.ioGlobal edge containersfly.io
DokploySelf-hosteddokploy.com
CoolifySelf-hostedcoolify.io

AWS ECS (Elastic Container Service)

Recommended to use SST AWS ECS to deploy the container.

Your NEXTDEVKIT application is now containerized and ready for deployment! 🐳🚀