rsnext/examples/with-docker
Tanmay Laud f00ad581a1
Added .gitignore to examples that are deployed to vercel (#15127)
Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
2020-07-16 10:52:23 -04:00
..
pages Update Examples for Fast Refresh (#13068) 2020-05-18 17:44:18 -04:00
public [Examples] Added public folder to with-docker example (#12879) 2020-05-18 13:08:28 -04:00
.dockerignore Add docker example (#4261) 2018-05-05 04:12:56 -07:00
.gitignore Added .gitignore to examples that are deployed to vercel (#15127) 2020-07-16 10:52:23 -04:00
Dockerfile Add docker example (#4261) 2018-05-05 04:12:56 -07:00
Dockerfile.multistage fixing the docker multi-stage build failures (#14513) 2020-06-24 03:56:41 +00:00
package.json Remove isomorphic-unfetch from examples (#12948) 2020-05-15 22:23:55 +02:00
README.md Suggest npx over npm init (#13637) 2020-06-01 17:36:57 +00:00

With Docker

This example shows 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:

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/vercel/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 \
  next-app

or use yarn build-docker-multistage