Use Case
Your Next.js service runs via Compose. You need branch-isolated environments and deterministic port mapping per workspace.
Use this when your app runs in containers and you want workspace-isolated host ports with clear container health visibility.
Your Next.js service runs via Compose. You need branch-isolated environments and deterministic 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 an isolated env file. Symlink can reduce duplication, but one edit impacts all linked workspaces. Point cp at whatever seed file your repo keeps — Spaces does not provide a built-in shared env file.
SPACES_FRONTEND_PORT=$SPACES_FRONTEND_PORT docker compose up --buildThe process keeps Compose attached in one terminal, which is useful for live logs and interactive shutdown.
$SPACES_FRONTEND_URLThis targets the workspace-specific service mapping. Without named services, one workspace can accidentally open another workspace's frontend.
docker compose stop
# or
docker compose downdocker compose stop: stop containers but keep networks/volumes/containers for faster resume.docker compose down: remove containers and network; cleaner reset, slower next startup.stop for day-to-day pause/resume; use down when you need a clean teardown.