Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

How to Containerize a Next.js App With Docker

Containerize a Next.js app with the right output mode, a reproducible multi-stage Dockerfile, non-root runtime, build and run commands, static export instructions, and production troubleshooting.
Length10 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a production Next.js application that uses server rendering, API routes, or incremental static regeneration, set output: "standalone" in next.config.js and build a multi-stage Docker image. Install dependencies in one stage, compile the application in a builder stage, then copy the traced standalone runtime into a small, non-root runner that starts server.js on port 3000.

If every route is generated at build time and the site has no server-side features, use output: "export" instead. Next.js writes static files to out, which you can serve with Nginx or another static host. Export mode is simpler and does not provide server-side rendering or API routes.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the Next.js Docker deployment mode first

Your output setting determines what the image must contain and what kind of process runs in production. Choose it before writing the Dockerfile.

Decision Standalone output Static export
Next.js setting output: "standalone" output: "export"
Use it when The application needs server rendering, API routes, incremental static regeneration, or other server features Every route can be generated at build time and the site is entirely static
Build output .next/standalone, plus .next/static and public when those directories are used out
Production runtime Node.js running the generated server.js Nginx or another static-file server
Example container port 3000 8080 in the Docker guide’s Nginx example; your Nginx configuration may listen on another port
Operational trade-off Supports the full server feature set, but requires a Node process and a runtime image Smaller and simpler to serve, but server-side rendering and API routes are unavailable

Next.js documents Docker deployments as supporting all Next.js features, and a Docker-capable provider can host the resulting image, including a Kubernetes cluster or a cloud container service. That broad support applies to a server deployment such as standalone; an exported site intentionally gives up server features.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses | Anti UV Ray, For Computers & Gaming, Square Frame, Eyewear for Men and Women
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.

Prepare the project for a reproducible image

Use a lockfile and the project build script

Keep package.json and the lockfile that belongs to your package manager in the repository. The dependency stage should install from that lockfile rather than resolving a fresh dependency graph on every build. With npm, the reproducible command is npm ci. Yarn and pnpm have their own frozen-lockfile or CI modes; use the equivalent command for the lockfile in your project.

The Dockerfile below assumes npm and a committed package-lock.json. If the project uses Yarn or pnpm, copy its manifest and lockfile instead and replace the install and build commands with the project’s documented equivalents. Do not copy an npm lockfile into a Yarn or pnpm build merely to make the example run.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Confirm that a production build works outside Docker

Run the same build script locally before troubleshooting containers:

npm ci
npm run build

The build command must be the script your project defines. Most projects use npm run build, but Docker does not require that exact script name; it only runs the command you specify.

Set the output mode in Next.js

For a server-capable application, add the standalone setting to next.config.js (or the equivalent configuration file format used by your project):

/** @type {import('next').NextConfig} */
const nextConfig = {
  output: "standalone",
};

module.exports = nextConfig;

For a site that is genuinely static, use:

/** @type {import('next').NextConfig} */
const nextConfig = {
  output: "export",
};

module.exports = nextConfig;

Do not select export simply because it produces a smaller image. It is appropriate only when all routes and data requirements can be satisfied at build time and no request-time server code is needed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed

Keep the Docker build context small

Create a .dockerignore file at the project root. A small context speeds up transfers to the Docker daemon and prevents local build artifacts from being copied over the files created inside the image.

node_modules
.next
out
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
*.log
.git
.gitignore
Dockerfile
.dockerignore

Adjust the list for your repository. For example, do not ignore a file that is intentionally required by the build. The important exclusions are local node_modules, previous Next.js output, logs, and unrelated files. Keep secrets out of the build context entirely; ignoring a secret file is not a substitute for removing it from the directory or repository.

Build a production image with standalone output

This multi-stage Dockerfile separates dependency installation, compilation, and runtime assembly. The final stage contains the traced standalone application rather than the complete source tree and development toolchain.

FROM node:22-alpine AS deps
WORKDIR /app

COPY package.json package-lock.json ./
RUN npm ci

FROM node:22-alpine AS builder
WORKDIR /app
ENV NODE_ENV=production

COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build

FROM node:22-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV PORT=3000

RUN addgroup -S nextjs && adduser -S nextjs -G nextjs

COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nextjs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nextjs /app/.next/static ./.next/static

USER nextjs
EXPOSE 3000
CMD ["node", "server.js"]

The node:22-alpine tag is an example base image choice, not a promise that this is the correct image for every future build. Review and pin a current Node.js LTS base image for your release process. Image tags and their security patches change over time; record the version or digest you have approved and rebuild when your maintenance policy calls for an update.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What each stage does

  • Dependencies: Copying only package.json and package-lock.json before running npm ci lets Docker reuse this layer when application source changes but dependencies do not.
  • Builder: The source is copied after dependencies are installed. npm run build produces the Next.js output, including the traced standalone server when the configuration uses output: "standalone".
  • Runner: The image receives the standalone directory, the static assets under .next/static, and the public assets. It does not need the compiler, npm cache, or development dependencies that were used to build the application.
  • User and ownership: A dedicated nextjs group and user are created, copied files are assigned to that user where needed, and the process starts with USER nextjs instead of root.
  • Command and port: The generated entry point is server.js. The example advertises port 3000 and starts Node with that file.

Handle projects without a public directory

The official standalone pattern copies public because many applications use it for images, icons, or other files served unchanged. If your repository has no public directory, the corresponding COPY --from=builder /app/public ./public line will fail. Remove that line, or create the directory if your application expects it. Keep the copies of .next/standalone and .next/static; they serve different purposes.

Build and run the standalone image

  1. From the directory containing the Dockerfile, build the image:
    docker build -t nextjs-sample .
  2. Start a container and publish the application port to the host:
    docker run -p 3000:3000 nextjs-sample
  3. Open http://localhost:3000 from the host. The first port is the host port; the second is the port inside the container. If you choose a different host port, keep the container side at 3000 unless you also change the runtime configuration.
  4. Stop the process with Ctrl+C in the foreground, or use the normal Docker container lifecycle commands when running it detached.

When the container starts successfully, its process is the generated Node server rather than the Next.js development server. Do not use next dev as the production container command.

Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)

Pass configuration and secrets safely

Do not bake credentials, API keys, private certificates, or other secrets into the image or Docker build context. Supply runtime configuration through the secret mechanism provided by the environment where the container runs. The exact command differs between local Docker, a managed container service, and Kubernetes, but the principle is the same: the image should be reusable without containing an environment-specific secret.

Next.js configuration and environment variables that are evaluated during npm run build affect the generated output. If you change such a value, rebuild the image; changing only the running container’s environment cannot retroactively alter files already produced by the build. Likewise, rebuild after changing dependencies, either lockfile, or the Next.js configuration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep deployment-specific values outside the Dockerfile when possible. A Dockerfile ENV line is visible as image metadata and is therefore unsuitable for sensitive values. The example sets only non-secret process settings, such as NODE_ENV and the application port.

Use a static export when the site needs no server

With output: "export", a production build writes the generated site to out. There is no standalone server.js to run. The resulting directory can be uploaded to a static host or copied into an Nginx image.

Build the export

npm ci
npm run build
ls out

The build must be able to generate every route and required piece of data without request-time server execution. API routes and server-side rendering are not available in this mode, so a route that depends on those features requires a server deployment instead.

Serve the output with Nginx

A minimal static image can copy the generated files into Nginx’s document root:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC
FROM nginx:alpine
COPY out /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

The Docker guide’s export example uses port 8080 for its Nginx setup. If your Nginx configuration listens on the default port 80, publish it with a host-to-container mapping such as:

docker build -t nextjs-static .
docker run -p 8080:80 nextjs-static

If you deliberately configure Nginx to listen on 8080, publish 8080:8080 instead. The published host port and the port in the Nginx configuration must agree. Static routing behavior also depends on the server configuration; verify direct navigation to the routes your exported application generates.

Understand what standalone tracing copies

Standalone output is designed to include the files and dependencies needed to run the application, rather than requiring the entire project and full node_modules tree at runtime. The traced server is placed under .next/standalone. The static browser assets are separate, which is why the runner copies .next/static as well. Files in public are also separate and must be copied when the application uses them.

Copying only .next/standalone is a common source of missing styles, scripts, or images: the server can start while browser assets return 404 responses. Treat the three paths as distinct parts of the standalone deployment and check each one in the built image.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Deploy the image to a container platform

Push the image to the registry used by your hosting platform, then configure the platform to start the image and route traffic to the container port. A Docker-capable provider can host a Next.js container; the same image can be used on a virtual machine with Docker, a managed container service, or Kubernetes.

  • Configure the service’s container port to match the process: 3000 for the standalone example, or the port your Nginx configuration actually listens on for an export.
  • Provide runtime environment and secrets through the platform’s environment or secret settings rather than committing them to the image.
  • Use a health check that exercises an appropriate application endpoint for your deployment. The endpoint and check syntax are platform-specific, so keep them in the platform configuration rather than hard-coding a provider-specific command into this guide’s Dockerfile.
  • Retain the exact image tag or digest deployed so a rollback can reproduce the previous runtime.
  • Rebuild and redeploy after dependency, lockfile, Next.js configuration, or build-time environment changes.

Next.js describes Docker as a deployment option with support for all Next.js features, but the operational details—registry authentication, ingress, scaling, logs, and secret storage—belong to the container platform you select.

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.

Troubleshoot the failures that matter most

The build cannot find a lockfile

The dependency stage copies package-lock.json. If the project uses Yarn or pnpm, that file will not exist. Change the Dockerfile to copy the correct manifest and lockfile, then use the package manager’s frozen or CI install mode. Do not disable lockfile enforcement just to get a build through; reproducibility is the reason the file is copied first.

server.js is missing when the container starts

Check that the Next.js configuration actually contains output: "standalone" and that the builder completed npm run build. The runner must copy /app/.next/standalone into its working directory. If the project uses export mode, there is no standalone server.js; use a static server image instead.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Pages load but CSS, JavaScript, or public images return 404

Verify that the runner copied .next/static and, when applicable, public. Those paths are not automatically merged into the standalone directory by the Dockerfile. Rebuild the image after correcting the copy commands so stale layers do not hide the change.

The container runs but cannot be reached from the host

Confirm that the process is listening on the container port you published and that the two ports in docker run -p host:container are in the intended order. The standalone example uses 3000:3000. An export served by default Nginx commonly uses a mapping such as 8080:80; publishing 8080:8080 will not work unless Nginx is configured to listen on 8080.

A copied directory causes a Docker build error

Check the build context and .dockerignore. Ignoring public, package-lock.json, or another required input makes it unavailable to COPY. Conversely, if public truly does not exist, remove its copy instruction as described above.

Changes do not appear after rebuilding

Dependency and source layers are cached independently. A changed lockfile invalidates the dependency layer; a changed source file invalidates the builder layer. If a changed build-time environment variable or Next.js setting is not reflected, ensure the image was rebuilt and that the new image tag is the one being run.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Production checklist

  • Choose standalone for server rendering, API routes, incremental static regeneration, or other server features; choose export only for an entirely static site.
  • Commit the package-manager lockfile and use its frozen or CI installation mode.
  • Use a multi-stage build so compilers, caches, and development dependencies stay out of the final image.
  • Review and pin a current Node.js LTS base image; image tags and security updates change regularly.
  • Keep .dockerignore focused on local dependencies, build output, logs, and unrelated files.
  • Copy .next/standalone, .next/static, and public as applicable.
  • Run the standalone process as a non-root user and preserve ownership of copied files.
  • Keep secrets out of the image and provide them through the hosting platform’s runtime secret mechanism.
  • Expose and publish the port that the process actually listens on.
  • Rebuild after dependency, lockfile, Next.js configuration, or build-time environment changes.
  • On macOS or Windows, consider the native Next.js development command for local development when filesystem performance makes bind-mounted Docker development impractical. Use the production image for production validation rather than treating the development server as the deployment runtime.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.