Remove the duplicated PNPM_VERSION pin from devcontainer.json build args and the Dockerfile ARG (which had drifted to 11.5.3 vs package.json's 11.5.0). Corepack now reads package.json#packageManager at runtime; set COREPACK_ENABLE_DOWNLOAD_PROMPT=0 so first-use provisioning is non-interactive. Update docs accordingly.
6.3 KiB
Dev Containers
This repository includes a Dev Container configuration to provide a consistent local development environment in VS Code.
What It Provides
- Node-based development image defined in .devcontainer/Dockerfile
- Workspace configuration in .devcontainer/devcontainer.json
- pnpm provisioned by Corepack from
package.json#packageManager(single source of truth) - Non-root development user configuration (node)
- Persistent pnpm store volume for faster reinstall times
Daily Workflow
- Open the repository in VS Code.
- Run Dev Containers: Rebuild and Reopen in Container when prompted (or from Command Palette).
- Wait for the post-create step to finish package installation.
- Work as usual: run tests, lint, and Nx targets from the integrated terminal.
Typical day-to-day actions:
- Rebuild after changing .devcontainer/Dockerfile or .devcontainer/devcontainer.json
- Reopen in container after dependency or toolchain updates
- Keep local Docker Desktop running before opening the container
Running Nx Targets From the Workspace
From the repository root (inside the container terminal), run Nx targets with the package manager wrapper.
Common examples:
pn nx test <project>pn nx build <project>
You can replace <project> with any workspace project name, for example core, content-services, or process-services-cloud.
Tip: to discover available projects and targets, run pn nx show projects and inspect each project's project.json (or workspace configuration).
Nx Daemon and Graph Ports in Dev Containers
For this repository's VS Code Dev Container, Nx daemon is enabled (NX_DAEMON=true) to speed up repeated local Nx commands by keeping project graph state warm between runs.
Notes:
- Avoid forcing
CI=truein day-to-day dev containers if you want daemon benefits. - Keep
CI=truefor real CI pipelines and short-lived/ephemeral containers. - If needed, disable daemon for a single command with
NX_DAEMON=false pn nx <target>.
When running Nx commands, VS Code may show a notification about a port being opened by Nx Graph. This is expected when Nx serves the graph UI locally; it is typically a localhost-only temporary port used for visualization.
Git Operations and Signing
The container is set up so you can do all Git work — including signed commits and pushes — inside it, using your host credentials and settings. Your private keys never enter the container: only the agent socket is forwarded.
Option A: Commit and Sign in Container (Recommended)
The VS Code Dev Containers extension wires this up automatically:
- Your host
.gitconfig(includinguser.signingkeyandcommit.gpgsign) is copied into the container. - Your host
gpg-agentis forwarded (this is whygnupg2is installed in the image), and your GPG public keys are imported into the container. - Your host SSH agent is forwarded, so
git pushover SSH uses your host keys.
One-time host setup (this is what gets copied in):
git config --global user.signingkey <YOUR_KEY_ID>
git config --global commit.gpgsign true
Then work entirely inside the container:
gpg --list-secret-keys # verify the forwarded key is visible
git commit -S -m "your message" # -S optional when commit.gpgsign is true
git push
If signing fails with gpg failed to sign the data / no secret key, the agent
forwarding did not attach — rebuild the container or reload the VS Code window.
Note: the automatic gitconfig / GPG / SSH forwarding is a feature of the VS Code Dev Containers extension. If you run this configuration via the plain
@devcontainers/cli, mount~/.gnupg,~/.gitconfig, and the agent sockets yourself, or fall back to Option B.
Option B: Sign Commits on Host
For the strongest key isolation, keep signing on the host:
- Keep private signing keys only on the host.
- Do normal development in the container.
- Stage and commit from a host terminal in the same repository checkout
(for example,
git commit -S ...).
Good fit when your policy forbids forwarding signing agents into containers.
Option C: Unsigned Commits in Container, Signed Merge in CI/Host
- Commit in container without local signing.
- Enforce signing at merge/release time using host or CI controls.
This can simplify local setup for contributors while preserving integrity checks in protected branches.
Practical Daily Pattern
- Code, lint, and test in the container.
- Commit and sign in the container using the forwarded host keys.
- Push from the container (SSH agent or
ghcredentials are forwarded). - Keep branch protection checks active (status checks, review, signature policy if used).
Updating Base Image Safely
When updating the base image digest in .devcontainer/Dockerfile:
- Keep the FROM line digest-pinned for reproducibility
- Do not add an inline trailing comment on the same FROM line
- Put comments on separate lines above the FROM line
Why: some Docker/Buildx parser combinations can fail with:
FROM requires either one or three arguments
even when the digest itself is valid.
Quick Troubleshooting
If container startup fails:
- Verify Docker Desktop is running.
- Build the Dockerfile directly to isolate parser/build issues.
- Rebuild and Reopen in Container after fixes.
Useful files to inspect:
- .devcontainer/devcontainer.json
- .devcontainer/Dockerfile
- VS Code Dev Containers logs under your local VS Code logs directory
Nx Daemon Not Starting in Container
If NX_DAEMON=true is set but pn nx daemon still reports that the daemon is not running, Nx may have persisted a stale disable marker from a previous startup failure.
Recovery steps:
-
Reset Nx local state:
pnpm nx reset -
Run any Nx command to trigger daemon startup:
pnpm nx show projects -
Verify daemon status:
pnpm nx daemon -
If still not running, inspect logs:
cat .nx/workspace-data/d/daemon.log
Notes:
- In Docker/dev containers, Nx disables daemon by default unless explicitly enabled.
- This repository enables it via
NX_DAEMON=truein .devcontainer/devcontainer.json.