rsnext/examples/with-docker
Shu Uesugi 6804039e94 Make example READMEs more consistent (#10124)
* npx create → npm init

* Fix inconsistent instructions

* Update amp-first

* Update with-graphql-react

* with-firebase-cloud-messaging

* Update with-higher-order-component

* change create-next-app url

* Update create-next-app instruction

* Update instructions to use npm instead of npx

* Move "the idea behind the example" to top

* Rename

* Rename

* Update contributing.md with a README template
2020-01-16 23:23:56 +01:00
..
pages Improve linting rules to catch more errors (#9374) 2019-11-10 19:24:53 -08:00
.dockerignore Add docker example (#4261) 2018-05-05 04:12:56 -07:00
Dockerfile Add docker example (#4261) 2018-05-05 04:12:56 -07:00
Dockerfile.multistage Update the docker multistage to copy only the necessary files (#9899) 2020-01-03 11:36:04 +01:00
next.config.js Improve linting rules to catch more errors (#9374) 2019-11-10 19:24:53 -08:00
package.json Update the docker multistage to copy only the necessary files (#9899) 2020-01-03 11:36:04 +01:00
README.md Make example READMEs more consistent (#10124) 2020-01-16 23:23:56 +01:00

With Docker

This example show how to set custom environment variables for your docker application at runtime.

The dockerfile is the simplest way to run Next.js app in docker, and the size of output image is 173MB. However, for an even smaller build, you can do multi-stage builds with dockerfile.multistage. The size of output image is 85MB.

You can check the Example Dockerfile for your own Node.js project section in mhart/alpine-node for more details.

How to use

Using create-next-app

Execute create-next-app with npm or Yarn to bootstrap the example:

npm init next-app --example with-docker with-docker-app
# or
yarn create next-app --example with-docker with-docker-app

Download manually

Download the example:

curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/with-docker
cd with-docker

Build it with docker:

# build
docker build -t next-app .
# or, use multi-stage builds to build a smaller docker image
docker build -t next-app -f ./Dockerfile.multistage .

Alternatively you can add these commands as scripts to your package.json and simply run

yarn build-docker or yarn build-docker-multistage

Run the docker image:

docker run --rm -it \
  -p 3000:3000 \
  -e "API_URL=https://example.com" \
  next-app

or use yarn build-docker-multistage

Deploy it to the cloud with now (download)

now --docker -e API_URL="https://example.com"