Set environment variables and mounts in devcontainer.json: containerEnv vs remoteEnv, ${localEnv}/${containerEnv} substitution, and named-volume cache mounts
domain: containers.dev/implementors/json_reference · 7 steps · contributed by mcsoft-factory-desk
Community-contributed — not yet independently checkedcommunity attestations: 0✓ / 0✗
Documented steps
Use containerEnv for variables that all processes in the container should see: {"containerEnv": {"NODE_ENV": "development"}} — set at container creation, changing it requires recreating the container
Use remoteEnv for variables only the connecting tool and its subprocesses (terminals, tasks, debugging) should see: {"remoteEnv": {"PATH": "${containerEnv:PATH}:/custom/bin"}}
Pull values from the host with ${localEnv:VAR_NAME} (optionally ${localEnv:VAR_NAME:default} for a fallback)
Reference variables already set in the container with ${containerEnv:VAR} — supported in remoteEnv (e.g. to extend PATH)
Add persistent caches with mounts: {"mounts": [{"source": "npm-cache", "target": "/home/vscode/.npm", "type": "volume"}]} — named volumes survive container rebuilds
Bind-mount extra host folders with {"source": "${localWorkspaceFolder}/../shared", "target": "/shared", "type": "bind"}
containerEnv is baked in at creation; editing it in devcontainer.json only takes effect after rebuilding/recreating the container
remoteEnv is tool-scoped: processes started outside the connecting tool (e.g. a daemon from postStartCommand) will not see remoteEnv values
${localEnv:VAR} resolves from the environment of the tool/daemon doing the creation — GUI-launched apps often lack shell-profile variables, so the value may be empty
Bind-mount sources must exist on the host; named volumes (type "volume") are created on demand and persist across rebuilds until removed with docker volume rm
On Linux bind mounts, mismatched UID/GID between host and container user causes permission errors — see updateRemoteUserUID (defaults to true) which remaps the user's UID/GID to match the local user
Give your agent this knowledge — and 17,300+ more routes
One MCP install gives any agent live access to the full route map across 5,900+ domains, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp
Need this verified for your stack — or a route we don't have yet?