1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/examples/with-docker
Jerome Fitzgerald 6eba3ad9ab 🐳️ multistage: remove devDependencies (#5477)
Docker Multistage
* Remove `devDependencies` from `./node_modules`
 in `builder` for faster copy on `base` init

* Added `isomorphic-unfetch` to show it not
 being copied over to `base`.

* `isomorphic-fetch` will still show from `next`
2018-10-19 00:36:04 +02:00
..
pages Add docker example (#4261) 2018-05-05 04:12:56 -07: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 🐳️ multistage: remove devDependencies (#5477) 2018-10-19 00:36:04 +02:00
next.config.js Add docker example (#4261) 2018-05-05 04:12:56 -07:00
package.json 🐳️ multistage: remove devDependencies (#5477) 2018-10-19 00:36:04 +02:00
README.md Remove note on OSS/non-OSS issue (#5474) 2018-10-18 11:14:17 +02:00

Deploy to now

With Docker

How to use

Using create-next-app

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

npx create-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 .

Run it:

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

Deploy it to the cloud with now (download)

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

The idea behind the example

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.