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

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Use a multi-stage Docker build and Next.js output: "standalone" for an application that needs server rendering, API routes, or incremental static regeneration. The final image runs the traced server.js as a non-root user on port 3000. Choose output: "export" only when every route is generated at build time; that produces an out directory for Nginx or another static host and does not include a Next.js server.

Choose the right Next.js output before writing a Dockerfile

Containerization starts with a deployment decision, not with a base image. Next.js has two relevant output modes, and they produce fundamentally different containers.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Decision Standalone output Static export
Next.js setting output: "standalone" output: "export"
Use it when The app uses server-rendered routes, API routes, middleware that needs a server, or incremental static regeneration Every page can be generated during the build and served as files
Build result .next/standalone, plus .next/static and usually public out
Runtime Node.js running Next’s generated server.js Nginx or another static-file server
Server-side rendering and API routes Supported Not available
Example container mapping Host port 3000 to container port 3000 The Docker example maps host port 8080 to Nginx’s container port 80
Operational complexity Requires a Node runtime and a long-running process Simple static serving, but no request-time Next.js execution

When in doubt, use standalone. Export is appropriate only after you have verified that no route, authentication flow, API endpoint, request-time data fetch, or other server feature must execute after the image is built.

Configure Next.js for a production container

Standalone configuration

Add the output setting to the configuration file used by your project. In a CommonJS configuration, next.config.js can contain:

#1 Best Overall
Sale
Compressed Air Duster,130000RPM Super Power Cordless Air Duster,Rechargeable Brushless Blower,3 Gear Adjustable Blower with LED Light,Dust Remover for Computer/House/Outdoor/Car
  • Powerful Turbo Fan:CAGIWIRU Electric Air Duster have reached speed up to 130000RPM,Can efficient remove dust and debris.With LED light and Three Adjustable Speed to meet with different cleaning tasks.
  • With Attached USB C Fasting Charging cable.Charing 3 hours,Enjoy up to 240 minutes of use on the lowest setting, For third speed can use for 25mins.with four charging options to meet with your needs.
  • Wide Application:Upgraded attached 5 different nozzles,making it suitable for a variety of scenes, such as car,pet, pc, keyboards, and other electronic devices. It also serves for office and home clean duster.
  • Handy Design & Portable:Cordless air duster electric nozzle is Light weight and small size, design and comfortable to hold and space saving, convenient to carry around. You can put it in your room or inside the car without taking up space.
  • Warranty & Support: Our Electric air duster comes with 5 years warranty and 24/7 customer service. During this period, if you have any questions,pls kindly feel free to contact us.
/** @type {import('next').NextConfig} */
const nextConfig = {
  output: "standalone",
};

module.exports = nextConfig;

If your project uses an ES-module configuration, use the equivalent exported object in next.config.mjs:

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

export default nextConfig;

During next build, Next.js traces the files and dependencies needed by the application and writes a self-contained server under .next/standalone. The generated directory does not automatically replace every project asset: the production image also needs .next/static, and it needs public if your application serves files from that directory.

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

Static-export configuration

For a genuinely static site, set:

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

module.exports = nextConfig;

The production build writes its files to out. There is no server.js to start. A static web server must deliver the files, and any route that cannot be resolved from generated files must be redesigned or generated at build time.

Prepare the project and build context

Keep dependency installation reproducible

Commit the lockfile that belongs to your package manager. Copy package.json and that lockfile before copying application source so Docker can reuse the dependency layer when only source files change. For npm, the reproducible install command is npm ci; Yarn and pnpm projects should use their corresponding frozen-lockfile or CI mode.

The examples below assume npm and a committed package-lock.json. Replace the install and build commands when your project uses another package manager, and keep the same stage boundaries.

Rank #2
EVEO® Screen Cleaner Spray Kit (Streak-Free) TV Screen Cleaner for Smart TV, Lcd, LEd, Oled | Computer Screen Cleaner Spray and Wipe Microfiber Cloth - TV, Monitor, Laptop, iPad, Car - 6.7oz 1 Pack
  • Screen Cleaner is Your Screen’s New Bestfriend! - EVEO is proud to present a screen cleaner that’s perfectly suited for your TV. Meet your new screen cleaner, computer screen cleaner, laptop cleaner, iPad cleaner, Macbook,tv cleaner or any other electronic device. Our screen cleaner spray and wipe along with the included plush microfiber cloth, easily removes dust, fingerprints & other smudges on the screen’s surface. Clean effectively for a streak-free screen
  • Gentle on your Screens - Our screen cleaner spray and wipes is compatible to be used even for the most sensitive LCD, LED, CRT, and OLED screens in proper use. Be at ease knowing that this product is compatible with all the major brands: LG, SONY, Samsung, Sharp, iPad, iPhone, Android screens, Kindle, PC monitors - we’ve got you covered! Can be used as LCD screen cleaner, tv cleaner, smart tv screen cleaner, and more
  • Premium Super Soft Plush Microfiber Cloth - Included in this efficient screen cleaning kit. This screen cleaner spray and wipe has our signature plush microfiber cloth specially designed to comply with screens and monitors and leave them streak-free. Has been shown to effectively absorbs stubborn stains, zero streaks, and no fiber shedding. Always use this together with our screen cleaner for the best results
  • Easy-to-Use Screen Cleaner Kit + microfiber cleaning cloth - The EVEO Screen Cleaning Kit will easily be your new favorite tool when it comes to taking care of the things you love most, quick and easy solution for a streak-free screen. Simply screw on the sprayer gun on the screen cleaner bottle. Spray the cleaning liquid onto the microfiber cloth, then wipe the screen until desired cleanliness & shine is achieved.
  • Quality Screen Care Kit Worth Purchasing - Enjoy a convenient Screen Cleaner anytime, anywhere you need it. Your satisfaction is our top priority. We stand behind the quality of our products and that’s why, you shouldn’t be worrying at all. We manufacture the Best Screen Cleaner. and can be used for laptop cleaning kit, laptop screen cleaner, tv screen cleaner for smart tv. MacBook screen cleaner, monitor cleaner or screen cleaner spray for electronic devices with microfiber cleaning cloth

Add a .dockerignore file

A small build context improves transfer time and prevents local artifacts or secrets from being copied into an image. A practical starting point is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
node_modules
.next
out
.git
.gitignore
Dockerfile
.dockerignore
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
*.log
.env*

Review this list for your application. Do not ignore a file that is required to compile the app, but do exclude local dependency trees, previous build output, logs, and environment files containing secrets. Docker sends the build context to the daemon, so a file excluded here is less likely to be copied accidentally.

Build a production image with standalone output

Complete multi-stage Dockerfile

Create a file named Dockerfile at the project root:

FROM node:22-bookworm-slim AS deps
WORKDIR /app

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

FROM node:22-bookworm-slim AS builder
WORKDIR /app

COPY --from=deps /app/node_modules ./node_modules
COPY . .

ENV NODE_ENV=production
RUN npm run build

FROM node:22-bookworm-slim AS runner
WORKDIR /app

ENV NODE_ENV=production
ENV PORT=3000
ENV HOSTNAME=0.0.0.0

RUN groupadd --system --gid 1001 nodejs 
  && useradd --system --uid 1001 --gid nodejs nextjs

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

CMD ["node", "server.js"]

The Node image tag in this example is an illustration of a pinned major-line choice, not a promise that it will remain the best LTS line. Select and regularly review a current Node.js LTS base image for your support window; tags and security patches change over time.

If the project has no public directory, remove the first COPY --from=builder /app/public ./public line or create the directory. A missing source directory causes that Docker step to fail. The other two copies are required for the standalone server and its browser assets.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
BladeHawks RGB Gaming Mouse Pad Extra Large Extended 31.5x12 Inch-Black
  • 【Large size】:Measuring 800 x 300 mm/ 31. 5×12 inches, which is wider and taller than others. Large mouse pad can perfectly fit your keyboard and mouse of any size, and there is also ample space for peripherals such as phones, tablets, etc.
  • 【LED backlight mouse pad】:Blade Hawks RGB mouse pad provides 7 static modes and 7 dynamic modes will give you the options you are looking for. Power-off memory function remembers the last lighting mode you selected. The super glow fiber Chroma will give you a colorful gaming setup that you want.
  • 【Anti-slip rubber base】:Made from Natural rubber, this gaming mousepad will firmly grip your desktop, allowing you to enjoy the ultimate precision in the games you are most passionate about. It also comes with a texture that enhances this ability even further.
  • 【Smooth and waterproof surface】: Micro-textured cloth surface, for extremely precise mouse control and a smooth movement. When liquid splashes on the gaming mouse pad, it forms water droplets and slides down. Will not delay your work or gameplay.
  • 【Plug and play】: This mouse and keyboard pad is powered by USB, plug and play, no driver required. One button control light modes. Press one time to change the lighting mode, press twice to change the brightness, press and hold about 3 seconds turn ON/OFF.

Why the stages are separate

  • Dependency stage: installs exactly what the lockfile specifies and forms a cacheable layer.
  • Builder stage: contains source code, compilers, and development dependencies long enough to run npm run build.
  • Runner stage: receives only the traced runtime and static assets, leaving source, package-manager caches, and build tooling out of the production image.

This separation reduces the final image’s attack surface and size compared with starting a container by copying the entire working directory and running a development install.

Run the standalone image locally

  1. Build from the directory containing the Dockerfile:
    docker build -t nextjs-sample .
  2. Publish the container’s port 3000 on the host:
    docker run -p 3000:3000 nextjs-sample
  3. Open http://localhost:3000 and exercise a server-rendered page, a static asset, and each API route that the image is expected to provide.

The EXPOSE instruction documents the intended container port; -p 3000:3000 is what actually publishes it from Docker to the host.

Build a static-export image with Nginx

Use this path only after confirming that the application is static at build time. Keep the same dependency and builder concepts, but copy out into an Nginx runtime instead of copying a traced Node server.

FROM node:22-bookworm-slim AS deps
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci

FROM node:22-bookworm-slim AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
ENV NODE_ENV=production
RUN npm run build

FROM nginx:alpine AS runner
COPY --from=builder /app/out /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

Build and run it with:

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

Here, port 8080 is on the host and port 80 is inside the Nginx container. Visit http://localhost:8080. The static image has no Node process and cannot answer a Next.js API request or perform server-side rendering.

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.

Handle environment variables and secrets correctly

Separate values needed while compiling from values needed by the running container. A variable that Next.js substitutes into client bundles or otherwise evaluates during next build requires a rebuild when it changes. Changing a runtime environment variable alone cannot rewrite JavaScript that was already emitted into .next or out.

Rank #4
Sale
Vaydeer Wrist Rest for Keyboard and Mouse, Computer Ergonomic Wrist Support Pad, Soft Memory Foam Arm Cushion for Desk, Palm Hand Office Laptop Typing
  • 【Softer and More Comfortable】Vaydeer wrist rest has unique diamond pattern, which is the combination of softness and aesthetics. The materials of wrist rest are improved into higher quality memory foam and covered with silky smooth lycra. The computer wrist rest makes you as comfortable and cushiony as like rest your wrists on clouds.
  • 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist support. Based on ergonomic design, the unique concave shape is the perfect fit for your wrist joints. The wrist rest pad fits most computer keyboards and laptops, improve hand and wrist posture, release your wrist and arm stress.
  • 【Non-Slip Rubber Bottom】Featuring an anti-skid silicone base on the bottom, this wrist keyboard support stays firmly in place on your desk, preventing the padding from sliding around, ensuring stable and consistent wrist support during extended computer sessions.
  • 【Better Experience & Pain Relief】Our keyboard arm rest is beneficial to alleviate the soreness caused by direct contact and friction between your arm and a hard desk surface, reducing the risk of wrist fatigue or carpal tunnel. The soft texture of memory foam can evenly distribute the pressure around your wrists and provide good support with just enough give.
  • 【Helpful in Multiple Scenarios】Whether you're working, studying, writing, typing, gaming, this keyboard and mouse rest combo is an essential accessory to add comfort and support to your hands and wrists. It’s also a great gift for men, women, family, friend, coworker, gamer, teacher, etc.

Keep credentials, tokens, and private keys out of the Dockerfile, source tree, and build context. Supply runtime configuration through the deployment platform’s secret mechanism or an environment file that is not committed. For example, a local test can use:

docker run --env-file .env.production -p 3000:3000 nextjs-sample

Do not put a secret in an ARG, a committed ENV instruction, or a file copied into a layer. Image history and registries can retain those values even after a later layer appears to remove them.

Make the container production-ready

Run without root privileges

The runner stage creates a dedicated group and user, assigns ownership to the copied application files, and switches to USER nextjs. Keep that arrangement unless the application has a documented requirement for elevated privileges. Running as a non-root user limits the impact of a process compromise.

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

Pin and maintain the base image

Choose a current Node.js LTS line that your Next.js version supports, then review the tag and rebuild regularly for operating-system and Node security updates. A reproducible lockfile does not make an old base image safe, and a moving tag can change without a Dockerfile edit; record how your team reviews both.

Rebuild when inputs change

  • Run a new image build after changing dependencies or either lockfile.
  • Rebuild after changing next.config.js or next.config.mjs, because output mode and tracing are decided during the build.
  • Rebuild for environment values evaluated at build time.
  • Restart or redeploy the container for values intended only for runtime.

Keep development separate from production

Do not use the production runner as a replacement for the Next.js development server. On macOS and Windows, filesystem sharing can make bind-mounted Docker development noticeably slower; Next.js advises considering the native development command when filesystem performance is a concern. Build the image for production behavior, and use your normal local development workflow when rapid file watching matters.

Best Value
Sale
Under Desk Cable Management Tray No Drill, Metal Mesh Cable Management Under Desk with Clamp Mount, 2 Hole Cable Tray with Wire Management and Cord Organizer for Home Office Standing Desk
  • 【No Drill Mounted】Cable management tray can be assembled in as little as 3 minutes or less-simply. Side clips easily clampe the edge of desk, pass through the holes on the sides, and secure excess cables with baskets. Desk cable management supports inward or outward installation to meet your needs in different scenarios, and provides you with great convenience when collecting and organizing wires.
  • 【Rubber Pad Protects Desk】Wire organizer under desk built-in soft rubber pads on the clamp protect your desk from scratches, so you will not damage your furniture or office.
  • 【Sturdy and Beautiful】Cord management under desk is made of high-quality carbon steel and holds about 15 lbs. The wire basket has 2 holes on each side of the tray to enable your cables to pass freely. Cable baskets are suitable for desk thickness use from 0.4" to 2.4".
  • 【Space Saving & Keep Organized】Desk cable management tray holds all your power cords, outlet strips, USB hubs and computer transformers hidden from your feet, and the data cables will not enter the vacuum cleaner to keep your desk clean and tidy. Desk wire organizer is also suitable for use in the kitchen and outdoors.
  • 【Reduce Safety Risks】Cable tray under desk keeps all plugs away from your kids, no more worry about tripping. Using 2 holes wire tray saves extra space, helps you easily cabling and wire protection. The mesh design is not easy to accumulate dust, but avoids safety accidents caused by messy wires.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Deploy the image

Next.js documents Docker as a deployment option with support for all Next.js features when the image contains the appropriate runtime. Any provider that accepts Docker containers can host the image, including Kubernetes and cloud container services.

Standalone deployment checklist

  • Push the built image to the registry used by your deployment platform.
  • Configure the service to listen on container port 3000.
  • Provide runtime secrets through the platform’s secret store.
  • Set health checks against a route that does not require an interactive browser session.
  • Forward logs from the container’s standard output and error streams.
  • Scale replicas according to request load, remembering that in-memory state is local to a container.

The last point is an operational consequence of using multiple stateless containers: sessions, queues, uploads, and caches should use services designed to be shared when the application needs them. The Docker image itself should remain replaceable.

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

Static deployment checklist

  • Serve the contents of out from the static host’s document root.
  • Configure the host’s fallback behavior for the routing style your exported site uses.
  • Set the public hostname and caching policy at the static host or reverse proxy.
  • Do not configure a Node health check or expect API routes from this image.

Common failures and precise fixes

Symptom Likely cause Fix
npm ci fails immediately The lockfile is missing, does not match package.json, or belongs to another package manager Commit and update the correct lockfile, then use the package manager’s frozen CI install command
public copy step reports “not found” The project has no public directory Remove that copy instruction or add the directory if the application needs it
Page loads but CSS or JavaScript returns 404 .next/static was omitted from the runner image Copy /app/.next/static to ./.next/static in the same relative location
Container starts and exits The runner cannot find server.js, or the command was changed to a development script Verify output: "standalone", copy .next/standalone into the runner root, and run node server.js
Container is running but unreachable from another machine The port was not published, or the server is bound only to a loopback address Publish the port with -p and retain HOSTNAME=0.0.0.0 in the runner environment
API route works locally but not in the static image The app was built with output: "export" Switch to standalone and deploy the Node runner, or move that API behavior to a separate service
Changed environment value has no effect The value was embedded during next build Rebuild the image with the new build-time value; reserve runtime injection for server-read configuration
Image is unexpectedly large The final stage includes source, caches, or the complete node_modules tree Use the multi-stage runner and copy only standalone output and required assets
Files are writable only by root Files were copied before changing users without ownership correction Use --chown=nextjs:nodejs on copied runtime files and run as nextjs

Verify an image before releasing it

  1. Build from a clean checkout so ignored local artifacts cannot hide a missing file.
  2. Start the container with only the environment values that production will provide.
  3. Confirm the process runs as the intended non-root user.
  4. Check the home page, representative dynamic routes, static assets, API routes, and error responses.
  5. Stop and restart the container to detect accidental reliance on local state.
  6. Inspect the image layers and logs for credentials, development tools, source maps, or files that should not ship.
  7. Run the same image in the target orchestration environment and verify its configured port and health check.

Which approach should you choose?

Choose standalone when the application is a full Next.js server

Use the standalone Dockerfile when the app renders on demand, exposes API routes, uses incremental static regeneration, or otherwise needs Next.js to execute after deployment. The generated server and traced dependencies preserve those capabilities while avoiding an unnecessary copy of the entire development environment.

Choose export when the application is a file set

Use static export for documentation, marketing pages, or other sites whose complete route set can be generated during the build. Nginx or another static host is simpler to operate, but the trade-off is definitive: there is no request-time Next.js server, server-side rendering, or API route support in the exported image.

Final decision checklist

  • Can every route be generated before deployment? If not, do not use export.
  • Does the app need SSR, API routes, or ISR? Use standalone.
  • Is the lockfile committed and installed in CI mode?
  • Does .dockerignore exclude local dependencies, prior builds, logs, and secrets?
  • Does the builder run npm run build with NODE_ENV=production?
  • Does the standalone runner contain .next/standalone, .next/static, and required public files?
  • Does the static runner contain out and publish the expected host-to-container port mapping?
  • Does the process run as a non-root user with secrets supplied by the deployment environment?
  • Have you rebuilt after changing dependencies, Next.js configuration, or build-time variables?

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.