430e71a38d
### 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> |
||
---|---|---|
.. | ||
docker | ||
pages | ||
public | ||
styles | ||
.dockerignore | ||
.env | ||
.env.development.sample | ||
.env.production.sample | ||
.env.staging.sample | ||
.gitignore | ||
Makefile | ||
next.config.js | ||
package.json | ||
README.md |
With Docker - Multiple Deployment Environments
This examples shows how to use Docker with Next.js and deploy to multiple environment with different env values. Based on the deployment documentation.
How to use
Execute create-next-app
with npm, Yarn, or pnpm to bootstrap the example:
npx create-next-app --example with-docker-multi-env nextjs-docker-multi-env
# or
yarn create next-app --example with-docker-multi-env nextjs-docker-multi-env
# or
pnpm create next-app --example with-docker-multi-env nextjs-docker-multi-env
Enter the values in the .env.development.sample
, .env.staging.sample
, .env.production.sample
files to be used for each environments.
Using Docker and Makefile
Development environment - for doing testing
make build-development
make start-development
Staging environment - for doing UAT testing
make build-staging
make start-staging
Production environment - for users
make build-production
make start-production
Running Locally
First, run the development server:
npm run dev
# or
yarn dev
Open http://localhost:3000 with your browser to see the result.
You can start editing the page by modifying pages/index.js
. The page auto-updates as you edit the file.
API routes can be accessed on http://localhost:3000/api/hello. This endpoint can be edited in pages/api/hello.js
.
The pages/api
directory is mapped to /api/*
. Files in this directory are treated as API routes instead of React pages.