GitHub Codespaces devcontainer.json image pinning across create and rebuild
0 reputation · 13 Sept 2021, 07:34 UTC
0 reputation · 13 Sept 2021, 07:34 UTC
Keep the Codespaces container image identical between initial creation and subsequent rebuilds when devcontainer.json specifies an image by tag rather than digest.
Registry tags are mutable and may be retagged to different image contents. Codespaces does not enforce digest pinning, and lifecycle hooks such as postCreateCommand can run at different points during creation versus rebuild. Organization policies may also restrict base image selection. It is unclear whether a tagged image reference resolves to the same digest on rebuild as it did during creation, or whether a newer tag is pulled when repository files are unchanged.
What determines the resolved image digest during a Codespaces rebuild? Does rebuild reuse the originally created image digest or re-resolve the tag? How can a repository require digest pinning without relying on client-side enforcement?
35775 reputation · 13 Sept 2021, 19:16 UTC
A rebuild re-resolves the tag from the registry. It does not reuse the digest resolved at creation time unless devcontainer.json specifies an immutable digest reference. Mutable tags are looked up on each lifecycle event that rebuilds the container image.
The following reflects well-established devcontainer behavior:
mcr.microsoft.com/devcontainers/universal:2 is resolved to a SHA256 digest and cached for that session.docker://registry/image@sha256:...) skips tag resolution and pins the exact content.Treat the following as uncertain and verify against your current plan and region: whether intermediate caching layers persist across rebuilds, and how organization base-image policies interact with digest references. Policies may override or reject a pinned image, so the effective digest can differ from what is committed.
devcontainer.json with a digest-only URI, for example "image": "docker://ghcr.io/org/image@sha256:abc...".devcontainer.json contains a bare tag without a digest, preventing regressions before they reach Codespaces.Dockerfile.docker inspect --format '{{.Id}}' against the active container inside the Codespace terminal.One detail would change the recommendation: do you have administrative control over the organization Codespaces policy? If not, digest pinning in the repository may be overridden by policy, and the fix requires a policy update rather than a devcontainer change.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.