Building Your Application
Docker
You can containerize this stack and deploy it as a single container using Docker, or as a part of a group of containers using docker-compose.
Docker Project Configuration
Please note that Next.js requires a different process for build time (available in the frontend, prefixed by NEXT_PUBLIC) and runtime environment, server-side only, variables. In this demo we are using two variables, pay attention to their positions in the Dockerfile, command-line arguments, and docker-compose.yml:
DATABASE_URL
(used by the server)
NEXT_PUBLIC_CLIENTVAR
(used by the client)
Build and Run Image Locally
Build and run this image locally with the following commands:
docker build -t gellify-docker --build-arg NEXT_PUBLIC_CLIENTVAR=clientvar .
docker run -p 3000:3000 -e DATABASE_URL="database_url_goes_here" gellify-docker
Open localhost:3000↗ to see your running application.
Resources
- Dockerfile reference https://docs.docker.com/engine/reference/builder/↗
- Compose file version 3 reference https://docs.docker.com/compose/compose-file/compose-file-v3/↗
- Docker CLI reference https://docs.docker.com/engine/reference/commandline/docker/↗
- Docker Compose CLI reference https://docs.docker.com/compose/reference/↗
- Next.js Deployment with Docker Image https://nextjs.org/docs/deployment#docker-image↗
- Next.js in Docker https://benmarte.com/blog/nextjs-in-docker/↗
- Next.js with Docker Example https://github.com/vercel/next.js/tree/canary/examples/with-docker↗
- Create Docker Image of a Next.js app https://blog.tericcabrel.com/create-docker-image-nextjs-application/↗