This variant keeps the entire Next.js app inside a Docker volume and bind-mounts only src/
and public/
from your host.
You edit source files locally; everything else (package.json, config, node_modules) lives inside the container.
- 🧼 Clean host: no
node_modules
or config clutter - ⚡ Hot reload:
src/
andpublic/
are mounted directly → instant updates - 🔒 Stable environment: the app (and dependencies) are volume-backed
docker compose up --build
# open http://localhost:3000
On first run, the container scaffolds a Next.js app in a temporary directory (non-interactive), copies it into the volume, and seeds your host src/
and public/
if they are empty.
next-app:/app
— full app and configs (volume)./src:/app/src
— host source (bind mount)./public:/app/public
— host assets (bind mount)node_modules:/app/node_modules
— dependencies (volume)
# Start / rebuild
docker compose up --build
# Shell inside the container
docker compose exec frontend sh
# Production build & run
docker compose exec frontend sh -lc "npm run build && npm run start"
- If you previously ended up with a local
node_modules/
, delete it once (rm -rf node_modules
) so the container volume masks it. - To change configs like
next.config.*
orpackage.json
, exec into the container or copy files out/in as needed.