Commit Graph

106 Commits

Author SHA1 Message Date
Joseph 9a7061053e docs(examples): document env var handling in the Docker examples (#97968)
Improve with-docker example env var usage documentation.

Closes: https://github.com/vercel/next.js/issues/97959
2026-08-28 11:08:57 +02:00
Kowyo 5a22623262 example: remove duplicate items in .dockerignore (#91079)
Removed duplicate entries for cache and temporary directories.

```diff
- # Cache directories and temporary data
- .cache/
- .parcel-cache/
- .eslintcache
- .stylelintcache
- .turbo/
- .tmp/
# Cache directories and temporary data
.cache/
.parcel-cache/
.eslintcache
.stylelintcache
.swc/
.turbo/
.tmp/
.temp/
```

Co-authored-by: Joseph <joseph.chamochumbi@vercel.com>
2026-03-09 13:21:27 +01:00
Karl Horky a0d293fc08 with-docker: add new config file formats (#90731)
<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

### What?

Update config files in the `with-docker` example inside the
`.dockerignore`

### Why?

They are outdated

### How?

Add lines

cc @icyJoseph

---------

Co-authored-by: Joseph <sephxd1234@gmail.com>
2026-03-02 11:39:03 +01:00
Joseph 7643fc9483 example: restore .next handling for with-docker examples (#90651)
- Remove BuildKit cache mount on `.next/cache` that trapped fetch cache
in a volume unreachable by the runner stage
- Restore `mkdir .next && chown` in runner stage for writable prerender
cache
- Add commented-out `COPY .next/cache` line as opt-in for persisting
build-time fetch cache
- Apply same fixes to `Dockerfile.bun` (only needed the `mkdir`/`chown`,
it never had the BuildKit mount)

Closes #90648
2026-02-27 15:23:45 +01:00
Kristiyan Velkov d7732c57d6 [feat] Added Docker examples for standalone output and export output following best practices (#87069)
## What?

Modernizes the existing `with-docker` example and adds a new
`with-docker-export-output` example demonstrating different Next.js
deployment strategies with Docker best practices:

1. **`with-docker` (updated)** - Modernized to use App Router,
TypeScript, Tailwind CSS v4, and comprehensive Docker best practices.
Now includes both Node.js and Bun Dockerfile options, Docker Compose
with profiles, BuildKit cache mounts, and extensive documentation.

2. **`with-docker-export-output` (new)** - Demonstrates Next.js static
export mode deployment with Docker, offering two serving options:
**Nginx** (production-grade) and **serve** package (Node.js-based,
simpler setup). Includes optimized Nginx configuration, BuildKit cache
mounts, and comprehensive documentation.

Both examples include detailed documentation explaining Docker best
practices, implementation decisions, and deployment guidance.

## Why?

The existing `with-docker` example was using the Pages Router and
lacked:

- Modern Next.js patterns (App Router, TypeScript)
- Detailed documentation explaining Docker best practices and
implementation decisions
- BuildKit cache mounts for optimized build performance
- Bun runtime support as an alternative to Node.js
- Docker Compose configurations for easier local development
- Clear documentation about Node.js image variant choices (slim vs
Alpine)
- Examples demonstrating static export mode

These updates serve as comprehensive references for developers who want
to understand:

- How to Dockerize Next.js applications for different deployment
scenarios
- Why certain choices are made and how to optimize Docker setups for
production
- When to use standalone mode vs static export mode
- How to choose between Node.js and Bun runtimes
- How to choose between different web servers (Nginx vs serve) for
static sites

## How?

### `with-docker` example (updated)

- **Migrated to App Router** with TypeScript and Tailwind CSS v4
- **Multi-stage Dockerfile** with three stages: dependencies
installation, build, and runtime
- **Bun support** via `Dockerfile.bun` with optimized configuration
- **BuildKit cache mounts** for package manager stores (`npm`, `yarn`,
`pnpm`, `bun`) and Next.js build cache
- **Security best practices** with non-root user execution (built-in
`node` and `bun` users)
- **Docker Compose configuration** with profiles for Node.js (default)
and Bun
- **Comprehensive `.dockerignore`** to minimize build context size
- **Detailed README** explaining standalone mode benefits, Node.js image
choices, and deployment guidance
- **Deleted** `with-docker-standalone-output` (merged into this example)

### `with-docker-export-output` example (new)

- **Two Dockerfile options:**
- `Dockerfile` - Nginx-based serving with `nginxinc/nginx-unprivileged`
for security
- `Dockerfile.serve` - Node.js serve package-based serving for simpler
deployments
- **Multi-stage builds** for both options with separate dependency,
build, and runtime stages
- **BuildKit cache mounts** for package manager stores and Next.js build
cache
- **Production Nginx configuration** (`nginx.conf`) with gzip
compression, caching headers, and security best practices
- **Docker Compose configuration** supporting both serving options via
profiles
- **Comprehensive README** explaining static export mode, trade-offs
between Nginx and serve

### Docker best practices implemented (both examples)

| Practice | Description |
|----------|-------------|
| Multi-stage builds | Optimal image size reduction |
| Layer caching | Package files copied first |
| Minimal build context | Comprehensive `.dockerignore` files |
| BuildKit cache mounts | Faster subsequent builds |
| Security hardening | Non-root user execution |
| Corepack | yarn/pnpm version management |
| Package manager auto-detection | npm, yarn, pnpm support |
| Node.js 24.13.0-slim | Clear upgrade guidance |

## Breaking Changes

> **Warning**
> - `with-docker` now uses App Router instead of Pages Router
> - `with-docker-standalone-output` has been removed (merged into
`with-docker`)

---

**Note:** After this PR is approved and merged, I plan to open a
follow-up PR to update the Next.js documentation with proper links to
these Docker examples.

---------

Co-authored-by: Wyatt Johnson <accounts+github@wyattjoh.ca>
Co-authored-by: Joseph <joseph.chamochumbi@vercel.com>
Co-authored-by: kristiyan.velkov <kristiyan.velkov@ffw.com>
2026-02-20 15:57:11 +01:00
pji2918 2446efeaa6 fix: Change Dockerfile.bun to use group/useradd instead of addgroup/user (#87443)
<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change
-->

(sorry for my bad english)

### What?
Change `/examples/with-docker/Dockerfile.bun` to use group/useradd
instead of addgroup/user.

### Why?
Currently, the `docker build` command results in an error
`/bin/sh: 1: addgroup: not found`.
(related issue: oven-sh/bun#25441)

### How?
I changed the addgroup/user command to user/groupadd as a workaround.
[#](https://github.com/oven-sh/bun/issues/25441#issuecomment-3668036074)

fixes #87722.

---------

Co-authored-by: Joseph <sephxd1234@gmail.com>
Co-authored-by: Joseph <joseph.chamochumbi@vercel.com>
2025-12-23 18:34:44 +01:00
Jakob Klotz f41c809353 Docker example using bun (#83040)
### What?

Expanded the `with-docker` example for usage with `bun` and added build
instructions to the README.

### Why?

The existing example supports npm, yarn and pnpm, but not bun. 

### How?

- Add a separate Dockerfile.bun placed next to the existing Dockerfile,
which is more sensible for the existing solution.
- Dockerfile.bun uses the official oven/bun base image (different
runtime/tooling than node:18-alpine), so a separate file should be
clearer.
- Existing Docker commands in the README remain unchanged, because
Docker still uses the existing Dockerfile by default.
- The bun example can be built with: `docker build -f Dockerfile.bun -t
nextjs-docker .`

Related to #78465, #82998

---------

Co-authored-by: Joseph <joseph.chamochumbi@vercel.com>
Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
Co-authored-by: Joseph <sephxd1234@gmail.com>
2025-09-03 21:57:29 +00:00
JUNAID ALI KHAN c776c25b59 docs(docker): update base image to node:20-alpine in Docker examples (#83125)
This PR updates all example Dockerfiles that were using `node:18-alpine`
to `node:20-alpine`
to align with current LTS and address known issues in Node 18 images.

- examples/with-docker/Dockerfile
- examples/with-docker-compose/next-app/prod.Dockerfile
- examples/with-docker-compose/next-app/dev.Dockerfile
- examples/with-docker-multi-env/docker/development/Dockerfile
- examples/with-docker-multi-env/docker/production/Dockerfile
- examples/with-docker-multi-env/docker/staging/Dockerfile

I verified local builds for each example. No behavior changes;
docs/examples only.


https://github.com/vercel/next.js/issues/78465

---------

Co-authored-by: Joseph <joseph.chamochumbi@vercel.com>
2025-09-02 19:06:42 +02:00
Jam Balaya 6aafef389b examples: improve DX while copying command to create new project (#73463)
## Description

Follow up #38410.
Some examples remain the multiple commands in a single block, and we
couldn't use copy button to select one line.
With this change users would be able to copy the command (using their
choice package manager) with a single click using the github copy
feature.

CC: @samcx 

### Adding or Updating Examples

- [x] The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- [x] Make sure the linting passes by running `pnpm build && pnpm lint`.
See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md
2025-01-14 05:38:46 +00:00
Jam Balaya 1d5338f767 examples: update next-config-js document path (#73774)
## Description

Follow up #72465.
Update [`next-config-js`
document](https://nextjs.org/docs/canary/app/api-reference/config/next-config-js)
URL.

### Before

https://nextjs.org/docs/api-reference/next-config-js

### After

https://nextjs.org/docs/api-reference/config/next-config-js

### Adding or Updating Examples

- [x] The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- [x] Make sure the linting passes by running `pnpm build && pnpm lint`.
See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

CC: @samcx

Co-authored-by: Sam Ko <sam@vercel.com>
2024-12-17 21:14:33 +00:00
マルコメ f54d597563 examples: update gitignore files for parity for yarn recommendations (#71956)
## What?
Update examples `.gitignore` files for parity with [Yarn's official
recommendations](https://v3.yarnpkg.com/getting-started/qa#which-files-should-be-gitignored),
accounting for Yarn's modern Plug-n-Play functionality.

## Why?
New projects initialized with `create-next-app` presently add various
extraneous files from the Yarn cache to the initial commit. This is most
notable in the case of the Next SWC binary, which may exceed 100M in
some environments (empirically, 64-bit Darwin and WSL2 Ubuntu, and very
probably other unix/linux environments), and prevent users from pushing
their new projects to free GitHub repositories without rewriting the
commit history to exclude the extraneous files, or unnecessarily setting
up Git LFS to include them.

## How?
I have errored on the side of exclusion to enable users to push their
CNA projects to GitHub as-is and for parity with other package managers,
while still providing the opportunity to opt in to additional
functionality provided by modern Yarn.

These changes follow the recommendations for
**non**-[Zero-Install](https://yarnpkg.com/features/caching#zero-installs)
configurations, as Zero-Install functionality is an extension on top of
the base package manager experience, and may necessitate additional
configuration and present additional complications for unsuspecting
users, so I think it's best left up to the user to opt-in. On account of
the majority of publicly available Next.js-based projects comprising
general consumer-facing websites, it is my belief that the majority of
Next projects would not benefit from Yarn's Zero-Install functionality,
and that explicitly facilitating it by default would break status quo
with all other non-Yarn CNA projects.

Contrary to the example `.gitignore`s provided by Yarn, I've excluded
the `.yarn/sdks` directory as it contains IDE-specific tooling; I feel
it would be presumptuous for an environmentally-agnostic tool to target
and provide package-manager-specific tooling for specific editors. This
too should be left to the user to opt-in to and provide for their
project if they deem necessary.

I have retained the current `.gitignore`'s exclusion of the `/.pnp`
directory for backwards compatibility with older versions of Yarn (the
files therein have since been reallocated to the `.yarn` directory
addressed by these changes, but I am not clear on when that delineation
occurred or the prevalence of Yarn installations which depend on the
former convention). Maintaining the exclusion here, in the worst case,
implies additional downloads (on an order of magnitude merely similar to
using npm from the outset) rather than failure.

CC: @samcx 

### Adding or Updating Examples

- [x] The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- [x] Make sure the linting passes by running `pnpm build && pnpm lint`.
See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

Co-authored-by: Sam Ko <sam@vercel.com>
2024-12-17 01:24:53 +00:00
Duc Tran 7e73a3e48b update: remove unnecessary in Dockerfile (#72534)
<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->
### Updating Examples
- Remove unnecessary in Dockerfile
<img width="398" alt="image"
src="https://github.com/user-attachments/assets/63e6df3a-e9b8-42ed-bdd9-dd736131abbe">

Signed-off-by: ductnn <trannhuduc531998@gmail.com>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2024-11-18 15:36:17 +00:00
Jam Balaya d8c1875800 chore: add syntax parser directive to Dockerfile (#72380)
## What?
Add [`syntax`](https://docs.docker.com/reference/dockerfile/#syntax)
parser directive to the first line of the
[Dockerfile](https://docs.docker.com/reference/dockerfile/).

## Why?
To declare the Dockerfile syntax version to use for the build.
If unspecified, [BuildKit](https://docs.docker.com/build/buildkit/) uses
a bundled version of the Dockerfile frontend.

## How?
Append `# syntax=docker.io/docker/dockerfile:1` to the top of the
[Dockerfile](https://docs.docker.com/reference/dockerfile/).

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2024-11-06 23:22:46 +00:00
AliReza d85e2ae05e Add .npmrc file to Dockerfile for custom npm configurations (#72064)
### Description:
This PR updates the Dockerfile in the `examples/with-docker` folder to
include the `.npmrc` file in the dependency copy command.

### Original Command:
```dockerfile
# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
```

### Updated Command:
```dockerfile
# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc ./
```

### Reason for Change:
Including `.npmrc` allows for custom npm configurations, such as
`legacy-peer-deps=true`. Without this option, some installations can
fail due to unresolved peer dependencies, particularly for projects with
older dependencies.

This update ensures that any additional configurations specified in
`.npmrc` are applied during installation, improving Docker build
consistency and stability for projects with custom npm requirements.

### Diff:
```diff
- COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
+ COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc ./
```

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2024-10-30 15:57:09 +00:00
Florian Goße cc6d818131 fix(examples/with-docker): remove not needed files from docker context (#68668)
<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2024-09-16 20:18:48 +00:00
Bhavya Patel 854a7db88c examples: fix ENV warning for Docker example (#69091)
Co-authored-by: Bhavya031 <2021003493.adit@cvmu.edu.in>
Co-authored-by: Lee Robinson <me@leerob.io>
2024-08-25 22:19:53 -05:00
Alexey Avdeev fbeeb11ee8 examples: update "ENV key value" format format to "ENV key=value" (#69053)
Co-authored-by: Lee Robinson <me@leerob.io>
2024-08-25 22:13:35 -05:00
luo jiyin e4211f6ba2 fix: ENV warn info (#68486)
<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?
github action get me warm info 
"1 warning found (use docker --debug to expand):
- LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy
"ENV key value" format (line 25)"
 
### Why?

### How?

Closes NEXT-
Fixes #

-->
Closes #68487

---------

Co-authored-by: Jiwon Choi <devjiwonchoi@gmail.com>
2024-08-04 17:36:42 +00:00
Alex Yang 005a776c95 fix: missing file when build docker (#67718)
<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

Co-authored-by: Jiwon Choi <devjiwonchoi@gmail.com>
2024-07-13 05:36:33 +00:00
hrmny 64b718c661 chore: update prettier to 3.2.5 (#65092) 2024-05-08 21:47:14 +02:00
Koji Onishi 430e71a38d update Docker examples to specify HOSTNAME properly (#59756)
### What?

Update docker examples to correctly set HOSTNAME env variable for
standalone output

Related to PR:
https://github.com/vercel/next.js/pull/52804

### Why?
### TL;DR

The dockerfiile examples need to modified as that contains HOSTNAME
setting that apparently is not working as expected.

Related to Issue:
https://github.com/vercel/next.js/issues/58657

Affected examples:
https://github.com/vercel/next.js/tree/canary/examples/with-docker

https://github.com/vercel/next.js/tree/canary/examples/with-docker-multi-env

### Longer explanations

Based on [Docker
document](https://docs.docker.com/engine/reference/builder/#environment-replacement):
> You can also use environment variables with RUN, CMD, and ENTRYPOINT
instructions, but in those cases the variable substitution is handled by
the command shell, not the builder.

It means that when executing the last CMD ( `node server.js` ) in
Dockerfile samples, the HOSTNAME defined by prior `ENV` instruction is
simply ignored.

This causes problems typically when the host process sets HOSTNAME -
e.g. for instance when using AWS Fargate for deployment [we can't have
control over HOSTNAME](https://stackoverflow.com/a/52871552) set by the
host process. (also refer to the issue #58657 above)

### How?

Updated Dockerfilie samples, by setting HOSTNAME directly in CMD
instruction that launches nextjs server, not in the builder process.

Used this setting at my end (with AWS Fargate) to confirm that it fixes
the network problem.

Closes NEXT-
Fixes #58657

Co-authored-by: Sam Ko <sam@vercel.com>
2024-03-19 21:26:44 +00:00
Sam Ko 3f1ae54319 Revert "fix: permissions in with-docker example" (#63165)
Reverts vercel/next.js#63134

Closes NEXT-2783
2024-03-11 17:36:11 -07:00
Kinbaum 51665b3640 fix: permissions in with-docker example (#63134)
<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

### What

This pr addresses an issue in Docker where the cache and the creation of
its contents throw the following error:

```
[Error: EACCES: permission denied, mkdir '/app/.next/cache'] {
errno: -13,
code: 'EACCES',
syscall: 'mkdir',
path: '/app/.next/cache'
```

Co-authored-by: Sam Ko <sam@vercel.com>
2024-03-11 16:33:03 +00:00
JA b654effd53 fix(with-docker): resolve build with pnpm (#61529)
### Adding or Updating Examples

- Example:
[with-docker](https://github.com/vercel/next.js/tree/canary/examples/with-docker)
- Update: The latest change introduced in #61466 on the building process
of NextJS when the package manager is PNPM is currently throwing an
error (it works for npm though).

**To replicate the error:**

1. Checkout on the **with-docker** example
2. Install with PNPM so that it generates the pnpm-lock.yaml
3. Build the Docker image -> This will fail on the _builder stage_ step
that runs `pnpm run build`.

**Possible Solution:**
- Run `corepack enable pnpm` before building with pnpm
2024-02-01 19:32:57 +00:00
Stefan Generalao e0c63aca99 fix: dockerfile npm run build (#61466) 2024-01-31 18:46:33 +00:00
Sam Ko 8d13ab925e chore(examples): switch default from yarn to npm in Dockerfiles (#61348)
## Changes

- Switch default package manager to npm
- Fixes https://github.com/vercel/next.js/issues/61293

Closes NEXT-2291
2024-01-29 14:38:31 -08:00
Steven 4466ba436b chore(examples): use default prettier for examples/templates (#60530)
## Description
This PR ensures that the default prettier config is used for examples
and templates.

This config is compatible with `prettier@3` as well (upgrading prettier
is bigger change that can be a future PR).

## Changes
- Updated `.prettierrc.json` in root with `"trailingComma": "es5"` (will
be needed upgrading to prettier@3)
- Added `examples/.prettierrc.json` with default config (this will
change every example)
- Added `packages/create-next-app/templates/.prettierrc.json` with
default config (this will change every template)

## Related

- Fixes #54402
- Closes #54409
2024-01-11 16:01:44 -07:00
Luke Schlangen 0ea127c642 examples: add allow-unauthenticated option to cloud run deploy (#58792)
Co-authored-by: Lee Robinson <me@leerob.io>
2024-01-06 11:08:27 -06:00
Luke Schlangen a0b661de8d examples: remove broken deploy button (#58794) 2023-12-25 09:03:27 -06:00
Luke Schlangen 92f7d0c5e9 examples: add direct link to Dockerfile (#58793) 2023-11-29 18:54:44 -06:00
ihommani 70389d0cfd examples: update Dockerfile comment (#56646)
Co-authored-by: Lee Robinson <me@leerob.io>
2023-11-15 23:11:21 -06:00
leung018 66597be8a7 Add .yarn/install-state.gz to .gitignore (#56637)
### Reason for making this change
https://yarnpkg.com/getting-started/qa#:~:text=yarn%2Finstall%2Dstate.,your%20workspaces%20all%20over%20again.
In the official documentation of `yarn`, it is stated that `.yarn/install-state.gz` is an optimization file that developer shouldn't ever have to commit. However, currently, when running `create-next-app`, `.yarn/install-state.gz` is being commited.

### Remaining work
I apologize for only modifying one template initially to initiate the discussion first.

If this change is agreed upon,  it should be synchronized with other `.gitignore` templates. Would it be possible to follow a similar approach as in https://github.com/vercel/next.js/pull/47241? I would appreciate any assistance in syncing this change.
2023-10-18 16:34:48 +00:00
Rui Ying 49a891deb5 Fix the prerender cache update error with the example Dockerfile (#54870)
It seems the app router attempts to write its cache to both `.next/cache` and `.next/server` in docker.

This fix should fix standalone output server's error `Failed to update prerender cache... [Error: EACCES: permission denied...` when deployed in a docker container with the example Dockerfile.

Related discussion: https://github.com/vercel/next.js/discussions/51164
2023-09-01 17:19:13 +00:00
Mohamed A. Salah b7eb6d43b9 set hostname to 0.0.0.0 (#54342)
When I try to deploy to Google Cloud Run it fails after some
investigation I saw this line in

.next/standalone/server.js
```javascript
const hostname = process.env.HOSTNAME || 'localhost'
``` 
This some how make this log when i run docker 
```shell
- ready started server on 172.17.0.2:3000, url: http://172.17.0.2:3000
``` 
I don't know why it's logging this address even if the server running on
localhost.

So this my fix
Set hostname to 0.0.0.0 to avoid deployment failing on Google cloud run.
2023-08-21 19:05:57 +02:00
Tim Neutkens d60690e2bd Update Docker example to remove HOSTNAME (#54102)
With the latest changes in stable Next.js setting HOSTNAME is not longer required for the image to function correctly 👍 

Fixes #54093
2023-08-16 10:08:38 +00:00
Tim Neutkens c9fef184fd Revert "Move USER and remove redundant --chown from Dockerfile (#53441)" (#54046)
This reverts commit 39c06ae95e.

Based on
https://github.com/vercel/next.js/pull/53441#pullrequestreview-1578047015

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->
2023-08-15 10:37:17 +02:00
Stef 39c06ae95e Move USER and remove redundant --chown from Dockerfile (#53441)
### What?

In the Dockerfile example:

* Moves the `USER` command above the `COPY`s
* Removes the `--chown` on the `COPY`s 

> **Note**
> I don't know for 100% sure this won't have unintended side effects. Part of my motivation for opening this PR is to sense check whether we will be causing a regression by making this change in our own projects.
> 
> Please let me know if there's any concerns with this!

### Why?

Sonar security scanner flags this Dockerfile as having "security hotspots" due to the use of `--chown`

https://rules.sonarsource.com/docker/RSPEC-6504/

### How?

Make the `--chown`s redundant by setting the current user before doing the `COPY` commands.
2023-08-03 23:36:08 +00:00
Balázs Orbán 10f74a1d45 Revert "docker examples: improve perf by using COPY --link" (#53440)
Reverts vercel/next.js#52835 because it does not work on Google Cloud Run, which we mention in the README.md.

Closes #53425
2023-08-01 12:48:57 +00:00
Kévin Dunglas d8660bb059 docker examples: improve perf by using COPY --link (#52835)
### What?

Uses `COPY --link` instructions in Docker examples.

### Why?

This significantly [accelerates Docker builds and improves caching](https://www.howtogeek.com/devops/how-to-accelerate-docker-builds-and-optimize-caching-with-copy-link/).

This instruction is supported for more than 1 year and is now supported by almost all modern Docker installations.
We use it successfully for a while in [the API Platform distribution](https://github.com/api-platform/api-platform/blob/main/pwa/Dockerfile), which includes Next.js and is derived from these examples.

### How?

By updating the existing examples.
2023-07-18 20:44:46 +00:00
Eldar Amantay 0084166caa chore(docs): Add mentioning of HOSTNAME env variable for standalone output (#52804)
### What?

Update documentation to mention a `HOSTNAME` env variable for `standalone` output

Related to Feature: https://github.com/vercel/next.js/pull/44627 

### Why?

Current documentation mentions only `PORT` env, but does not mention `HOSTNAME` added in January

Affected documentation pages:

- https://nextjs.org/docs/app/api-reference/next-config-js/output

Affected examples:

- https://github.com/vercel/next.js/tree/canary/examples/with-docker
- https://github.com/vercel/next.js/tree/canary/examples/with-docker-multi-env

### How?

- Run examples
- Check documentation
2023-07-17 19:59:53 +00:00
Karl Horky 3ad55721d1 Remove incorrect entries for pnpm debug log (#47241)
**Reasons for making this change:**

- it is contained within `node_modules/`, which is already ignored
- the previous versions, which were not in `node_modules/`, did not have
a period at the beginning of the filename

Links to documentation supporting these rule changes:

**Changelog with proof here:**


https://github.com/pnpm/pnpm/blob/ba4b2db1f201640dad5d7ee9fe68a2d0defd6047/pnpm/CHANGELOG.md?plain=1#L3330

History:

- my PR to remove this from `github/gitignore` here:
https://github.com/github/gitignore/pull/4250
- First introduced in `github/gitignore` in
https://github.com/github/gitignore/pull/3732 by `@sakurayang` (merged
by `@martinwoodward`)

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-03-26 22:26:05 -07:00
Bennett Dams 7fde79a9e8 Define base image for multi-stage build (#45090)
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-02-07 15:21:20 -08:00
Luke Schlangen 836ac9cc7f bump node alpine to version 18 (LTS) (#45643)
Updating node version to LTS https://nodejs.org/
I tested locally and deploying to Google Cloud Run and build and deploy steps were successful in both cases.

## Documentation / Examples

- [x] Make sure the linting passes by running `pnpm build && pnpm lint`
- [x] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-02-07 02:31:38 +00:00
Craig Wheeler 57426a2849 Update Examples to use React 18 (#42027)
This PR updates the minimum version of React used by examples from 17.0.2 to 18.2.0.

Fixes #41975

## Bug

- [x] Related issues linked using `fixes #41975`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see `contributing.md`

## Documentation / Examples

- [x] Make sure the linting passes by running `pnpm build && pnpm lint`
- [x] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2022-10-28 17:43:20 +00:00
Crazy Urus d74f34021b Add --frozen-lockfile in Docker example when using pnpm (#41291)
It seems that lock file is used when using npm and yarn, but pnpm doesn't, complete this code.

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2022-10-10 12:10:14 +00:00
Steven be904d79ac Open deploy link in new window for examples (#40804)
Let's open the deploy link in a new window so the link isn't blocked
when running an an iframe, such as Stackblitz.

Previously, this would print the following error:

> Refused to display 'https://vercel.com/' in a frame because it set
'X-Frame-Options' to 'deny'
2022-09-22 09:33:36 -07:00
Henrik Wenz 92aafcbcf1 [Docs] Add config types to all examples (#40083)
<!--
Thanks for opening a PR! Your contribution is much appreciated.
In order to make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below.
Choose the right checklist for the change that you're making:
-->

## Summary

- Added jsdoc typing for all examples using `next.config.js`
- Added jsdoc typing for all examples using `tailwind.config.js`

## Documentation / Examples

- [x] Make sure the linting passes by running `pnpm lint`
- [x] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-08-31 16:41:22 -05:00
Jonas Strassel 638e6d16f8 chore(with-docker): don't copy package.json twice (#39896)
the directory `/app/.next/standalone` already contains a copy of the package.json so we can skip copying it before we copy the standalone dir

## Documentation / Examples

- [x] Make sure the linting passes by running `pnpm lint`
- [x] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-08-24 09:35:44 -05:00
Duc Tran b7997105a0 fix: use if...else in dockerfile (#39263)
* fix: use if-else in dockerfile

* fix: remove typo
2022-08-02 17:01:24 -05:00
Balázs Orbán 0a781dd675 fix: use if..elif..else in docker examples (#39072)
* fix: use `if..elif..else` in docker examples

* fix missing devDependencies for build

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-07-27 09:54:04 -05:00