Use case
Your Next.js service runs through Compose. You need branch-isolated environments and a predictable port mapping per workspace.
Use this when your app runs in containers and you want workspace-isolated host ports with clear container visibility.
Your Next.js service runs through Compose. You need branch-isolated environments and a predictable port mapping per workspace.
frontendSpaces assigns each service its own host port per workspace. Compose maps host $SPACES_FRONTEND_PORT to container port 3000.
services:
web:
build: .
ports:
- "${SPACES_FRONTEND_PORT}:3000"
environment:
- PORT=3000cp .env.example .envCopying .env gives each workspace its own env file; a symlink would reduce duplication, but one edit would then affect every linked workspace. Point cp at whatever seed file your repo keeps, Spaces has no built-in shared env file.
SPACES_FRONTEND_PORT=$SPACES_FRONTEND_PORT docker compose up --buildKeeping Compose attached in one terminal is useful for live logs and an interactive shutdown.
$SPACES_FRONTEND_URLThis targets the workspace-specific service mapping. Without a named service, one workspace could open another workspace's frontend by accident.
docker compose stop
# or
docker compose downdocker compose stop: stops containers, keeps networks, volumes, and containers for a faster resume.docker compose down: removes containers and the network, a cleaner reset with a slower next startup.stop for day-to-day pause and resume, and down when you need a clean teardown.