First, run the development server:
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun devOpen http://localhost:3000 with your browser to see the result.
You can start editing the page by modifying app/page.tsx. The page auto-updates as you edit the file.
This project uses a multi-stage Dockerfile to produce a lean, secure, production-ready image. Here is a breakdown of each stage:
# Stage 1: Install dependencies
FROM node:20-alpine AS deps- Uses the lightweight Alpine Linux variant of Node 20.
libc6-compatis installed because some native npm packages require it on Alpine.- Only
package.jsonandpackage-lock.jsonare copied first so Docker can cache the dependency layer — if those files haven't changed,npm ciis skipped on the next build.
# Stage 2: Build the application
FROM node:20-alpine AS builder- Copies installed
node_modulesfrom Stage 1 and the full source code. NEXT_TELEMETRY_DISABLED=1turns off Next.js anonymous telemetry.- Runs
npm run buildto produce the optimized.next/standaloneoutput.
# Stage 3: Production runner
FROM node:20-alpine AS runner- Starts from a fresh Alpine image — nothing from the build stage leaks into the final image (no source code, no dev dependencies, no build cache).
- A non-root system user (
nextjs) is created for security best practice — the container never runs asroot. - Only the files actually needed at runtime are copied:
public/— static assets.next/standalone/— the self-contained server.next/static/— pre-rendered CSS/JS chunks
- Port
3000is exposed and the app is started via the standaloneserver.jsthat Next.js generates.
Why multi-stage? Each FROM discards everything from the previous stage. The final image ships only the production runtime (~50–80 MB) instead of the full Node + source + dev dependencies (~600 MB+).
docker build -t nextapp:latest .docker run -p 3000:3000 nextapp:latestOpen http://localhost:3000 to verify the app is running inside the container.
- A free Docker Hub account.
- Docker installed and running on your machine.
docker loginYou will be prompted for your Docker Hub username and password (or Personal Access Token).
To use a token (recommended):
docker login -u yourusername
# Enter your Personal Access Token when promptedGenerate a token at: Docker Hub → Account Settings → Security → New Access Token
- Go to https://hub.docker.com/ and click Create Repository.
- Name it
nextapp(or any name you prefer). - Set visibility to Public or Private.
- Click Create.
Docker Hub requires images to be tagged in the following format:
<username>/<repository-name>:<tag>
| Part | Example | Description |
|---|---|---|
username |
codezelaca |
Your Docker Hub username |
repository-name |
nextapp |
The repository you created |
tag |
latest |
Version label (latest, v1.0, v1.0.1, etc.) |
docker build -t yourusername/nextapp:latest .Replace yourusername with your actual Docker Hub username. Example:
docker build -t codezelaca/nextapp:latest .To build with an explicit version tag as well:
docker build -t codezelaca/nextapp:v1.0.0 .docker push yourusername/nextapp:latestExample:
docker push codezelaca/nextapp:latestIf you tagged multiple versions, push each tag separately:
docker push codezelaca/nextapp:v1.0.0After the push completes, your image is publicly available at:
https://hub.docker.com/r/yourusername/nextapp
Anyone (or any server) can now pull and run your image without needing the source code:
docker pull yourusername/nextapp:latest
docker run -p 3000:3000 yourusername/nextapp:latest