Dev container
Open Postgres Checkpointer ships a dev container so the toolchain
(Python 3.13, uv, just, pre-commit, the GitHub CLI, a Docker
socket) is identical on every machine. This page is the contract it satisfies — read
it before changing .devcontainer/.
Using it
VS Code: Reopen in Container. From a terminal, the CLI does the same thing:
npx -y @devcontainers/cli@0.87.0 up --workspace-folder .
npx -y @devcontainers/cli@0.87.0 exec --workspace-folder . -- just test
--workspace-folder takes the host path. Never prefix these with DOCKER_HOST=…:
the container needs the rootful daemon, and .devcontainer/initialize refuses to run
against a rootless one because its uid remapping makes everything written through the
bind mount land owned by a phantom user.
Git over SSH works from both, through your host's SSH agent — see SSH.
What the definition guarantees
- No path spells the repository's directory name. Everything uses
${containerWorkspaceFolder}/${localWorkspaceFolderBasename}and workspace-relative script paths, so renaming or cloning the repo to a different directory does not break the container. - Container state lives in named volumes, not on the bind mount.
.venvis a named volume (open-postgres-checkpointer-venv-${devcontainerId}), because a venv shared with the host points at an interpreter that exists on only one side: hostuvdeletes and rebuilds it for host Python, containeruvthen does the same in reverse, and you pay a full resync on every switch.~/.sshis a per-worktree named volume too, and the uv cache is oneuv-cachevolume shared by every worktree of every project (uv supports concurrent access), as is the pre-commit store, onepre-commit-cachevolume at~/.cache/pre-commit(pre-commit locks the store while it clones repos and builds hook envs). Never runpre-commit gcorpre-commit cleanin a container:gcdeletes the hook repos of every config it cannot see, which is every other project's, andcleandeletes the whole store without taking the lock. uv never trims its cache on its own, so the shareduv-cachevolume only grows: now and then runuv cache prunefrom any one container (it waits for running uv commands rather than racing them), and neveruv cache clean, which empties the cache for every project. Two writes do reach the host on purpose:.devcontainer/initialize(which runs on the host) writes git-ignored files under.devcontainer/, and in a normal checkoutpost-create.shinstalls the pre-commit hooks into.git/hooks. - Git works from a linked worktree, not just the main checkout — see below.
remoteUseris non-root (vscode) with"updateRemoteUserUID": true, so files you create in the container are owned by you on the host.- Feature versions are locked.
devcontainer-lock.jsonis committed; check it withup --frozen-lockfile, which fails when a feature has drifted from the pinned digests (this project's CI does not build the container). Dependabot'sdevcontainersecosystem bumps features and the lock; regenerate it by hand by runningupwith the pinned CLI and committing the result. The base image tag (3-3.13-trixie) pins the image major and Debian release but still takes patch rebuilds. The uv feature'sversionoption is pinned (its default floats tolatest) and nothing bumps it automatically. - The Docker socket comes from the
docker-outside-of-dockerfeature's default mount and nothing else..devcontainer/post-start.shreports which half is missing — socket not mounted, or daemon unreachable — and never claims the container is ready after a failure. - The venv always matches
uv.lock.uv sync --locked --all-groupsruns on create (post-create.sh), on every start (post-start.sh, warn-only) and after every checkout/merge (theuv-syncpre-commit hook). A stale lock is reported, never silently re-resolved. pythonis the uv-managed interpreter from.python-version— in VS Code and underdevcontainer exec.post-create.shrunsuv python install --default,remoteEnvputs~/.local/binfirst on PATH, andUV_PYTHON_PREFERENCE=only-managedstops uv from picking the image's own Python. VS Code uses${workspaceFolder}/.venv/bin/python. A plaindocker execdoes not applyremoteEnv, so a barepythonthere is the image's;uv runis right everywhere.
Git identity
Git in the container needs a user.email, or every commit — and every test that makes
one — dies with unable to auto-detect email address. It does not get that by
mounting your ~/.gitconfig: on many machines that file is only an [include] /
[includeIf] shim pointing at a dotfiles checkout or a work/personal split, and those
paths are not mounted, so the include resolves to nothing in here.
Instead .devcontainer/initialize writes a flattened copy of your effective global
config — git config --global --includes --list, with the include.* / includeif.*
directives themselves dropped — to .devcontainer/.gitconfig.host, which is what
devcontainer.json bind-mounts read-only and post-create.sh pulls in with
git config --global include.path. It is rewritten on every up, so a change on the
host reaches the container on the next start, and it is git-ignored
(.devcontainer/.gitignore): it is host-specific and can hold credential settings.
Three things to know:
- Keys that name host binaries or paths, run drivers, or carry HTTP auth headers are
not copied:
credential.helper/credential.<url>.helper(VS Code forwards its own helper, and a copiedgh auth setup-gitblock would wipe it with its blankhelper =),core.pager,pager.*,interactive.diffFilter,core.hooksPath,core.excludesFile,core.sshCommand,core.askPass,core.fsmonitor,gpg.program,gpg.ssh.program,gpg.ssh.defaultKeyCommand,commit.template,filter.*,diff.external,diff.<driver>.textconv/.command,merge.<driver>.driver,difftool.*/mergetool.*cmdandpath,http.extraHeaderandhttp.<url>.extraHeader. Othercredential.*keys, such asuseHttpPath, still come across. Everything else is copied verbatim, and a valueless boolean ([core] bare) is copied astrue. - If
git config --global --includes --listfails on the host,initializestops rather than starting a container with no identity. includeIf "gitdir:…"conditions are evaluated against this repository, so a work/personal split gives the container the identity that repository would get on the host.
If the host has no user.email at all, post-create.sh says so and the container still
builds; set it on the host and recreate the container. post-create.sh sets
core.autocrlf, core.eol, init.defaultBranch and core.editor only when the host's
config does not already set them.
SSH
The container gets your host's SSH agent, never your key files: nothing in here —
an agent in bypass mode included — can copy a private key out, only ask the agent to
sign. ~/.ssh in the container is a per-worktree named volume, not your host ~/.ssh,
so your host ~/.ssh/config is not used either.
- VS Code forwards its own agent into the container automatically when one is running on the host.
- The CLI does not forward anything (
devcontainer exec,docker exec, agents), sodevcontainer.jsonbind-mounts the socket in$SSH_AUTH_SOCKat/ssh-agent.sockand setsSSH_AUTH_SOCKincontainerEnv, where every process sees it. The bind is a-vinrunArgs, not amountsentry: Docker Desktop for Mac shares a host socket through-vonly, and--mountfails withbind source path does not exist: /socket_mnt/.....devcontainer/initializerefuses to start whenSSH_AUTH_SOCKis set but empty or names something that is not a live socket, and warns (then mounts/dev/null) when it is unset — fine for CI. No agent running on the host? Source the script inhost_setup_scripts/(seeCONTRIBUTING.md). - Stale socket. The mount binds the socket path the host had when the container
was created, re-resolved on every container start. If the host agent restarts at the
same path, stop and start the container; if it comes back at a new path (a plain
ssh-agent -spicks a new one each time), recreate it with--remove-existing-container.post-start.shwarns when the agent is dead or has no keys loaded. - Host keys. github.com is verified against its published keys, pinned in
.devcontainer/ssh_known_hosts(mounted at/etc/ssh/ssh_known_hosts; refresh it when GitHub rotates a key)..devcontainer/initializestages your host's~/.ssh/known_hostsinto.devcontainer/.known_hosts.host(mounted read-only as a second trust file), and new hosts are learned into the volume's ownknown_hosts. - Commit signing works through the agent with no host paths: set
gpg.format sshanduser.signingKey "key::ssh-ed25519 AAAA…"(the public key, inline). Nothing here configures it for you.
Docker socket (accepted risk)
The docker-outside-of-docker feature hands the container the host's rootful Docker
socket, and access to it is root on the host: any process in the container, including
an agent, can docker run -v /:/host …. Keeping key files out of the container does not
contain host secrets while the socket is present. It stays because integration tests and
docker compose need it; remove the feature if you do not.
Git worktrees
In a linked worktree (git worktree add ../feature-x), .git is a file holding an
absolute pointer into the parent repository's .git/worktrees/<name> — a path outside
the workspace bind mount. Git inside the container would die during repository
discovery and onCreateCommand would exit 128 before anything else ran.
devcontainer.json mounts cannot branch on host state, so .devcontainer/initialize
runs on the host first and always produces the same two paths:
| path | normal checkout | linked worktree |
|---|---|---|
.devcontainer/.gitcommon → /gitcommon |
symlink to .git |
symlink to the parent's .git |
.devcontainer/.gitentry → <workspace>/.git |
symlink to .git (a no-op re-mount) |
a file reading gitdir: /gitcommon/worktrees/<name> |
Both are git-ignored (.devcontainer/.gitignore): they hold absolute host paths.
Two consequences inside the container:
- Never run
git worktree prune. The container can see the git common dir but not the host paths its sibling worktrees live at, so every one of them reads as prunable in here.post-create.shsetsgc.worktreePruneExpire never, which stopsgit gcfrom removing them — but a baregit worktree pruneignores that setting and deletes the metadata immediately. pre-commithooks are not installed from a worktree. Hooks live in the shared common dir, so installing them in here would repoint the parent repository's and every sibling's hook at a.venvinterpreter that exists in no host.post-create.shdetects this and skips, telling you to commit from the host.
When the container fails to build
A failed onCreateCommand / postCreateCommand is sticky: the CLI writes its
marker before running the command, so a plain up on the next attempt skips the
step that failed and hands you a half-built container. Recover by recreating it:
npx -y @devcontainers/cli@0.87.0 up --workspace-folder . --remove-existing-container
Two failures worth recognising by their message:
post-create: … /hooks is not writable— the container user's uid does not match yours on the bind mount. Check thatupdateRemoteUserUIDis stilltrueand that the daemon is rootful.initialize: … is not a git working tree— rungit init(and make a first commit) before starting the container; the definition mounts the repository's git directory.