78809a3d68
`with-docker-compose` contains everything needed to get Next.js up and running with Docker Compose. This example aims to provide an easy-to-use, Next.js app development and production environment, **all without Node.js being installed** on the host machine. This ensures a consistent development environment across Windows, MacOS, and Linux teams. I was inspired to create this, because the existing [with-docker](https://github.com/vercel/next.js/tree/canary/examples/with-docker) example only uses Docker to build the final production artifacts, not provide a development environment. Docker Compose easily syncs changes with containers for Hot Reloading, parallel builds, and networking, making it a powerful and consistent development tool. Developers can **easily extend this example** by modifying the YAML files to include Nginx, Postgres, and other Docker images. This example takes advantage of Docker multistage builds combined with the Next 12.1 [Output Standalone](https://nextjs.org/docs/advanced-features/output-file-tracing#automatically-copying-traced-files-experimental) feature, to create up to **80% smaller apps** (Approximately 110 MB compared to 1 GB with create-next-app). I also included an example without multistage builds, for developers who don't want to get into the weeds. I have been tweaking this Docker Compose setup over 3 years of real world use, but please let me know if anything can be improved.
24 lines
551 B
YAML
24 lines
551 B
YAML
version: '3'
|
|
|
|
services:
|
|
next-app:
|
|
container_name: next-app
|
|
build:
|
|
context: ./next-app
|
|
dockerfile: prod.Dockerfile
|
|
args:
|
|
ENV_VARIABLE: ${ENV_VARIABLE}
|
|
NEXT_PUBLIC_ENV_VARIABLE: ${NEXT_PUBLIC_ENV_VARIABLE}
|
|
restart: always
|
|
ports:
|
|
- 3000:3000
|
|
networks:
|
|
- my_network
|
|
|
|
# Add more containers below (nginx, postgres, etc.)
|
|
|
|
# Define a network, which allows containers to communicate
|
|
# with each other, by using their container name as a hostname
|
|
networks:
|
|
my_network:
|
|
external: true
|