Post-Create Phase
The last mile of workspace bootstrap — linking wrappers, configuring the shell, generating local configuration — once the container and content are in place.
- Kind
- Lifecycle
- Domain
- Environment & Tooling
- Applies at
.devcontainer/lifecycle/post-create.d/- Status
- Stable
- Source · managed
.devcontainer/lifecycle/post-create.d/README.md
01 Defines
The postCreateCommand phase: scripts in post-create.d/ that run once the workspace is fully available and the earlier creation-time phases have completed.
02 Applies when
- A task answers “what should be configured so this repository is ready for development”.
- Setup needs the container, the repository content, and earlier phases’ output all at once.
03 Boundaries
- Common or reusable tooling belongs in a devcontainer feature when one is available.
- Work that should repeat on every start or attach belongs in post-start or post-attach.
- Responses to repository content being created or updated belong in update-content.
Expected behaviour
- 01Scripts run once after creation, after on-create and update-content.
- 02Scripts are idempotent so workspace setup remains safe to rerun.
- 03The phase configures the workspace; it does not install shared toolchains.
- 04A failing script is reported and skipped by the runner; the workspace comes up without that last step.
Behaviour#
Post-create is the final creation-time phase. By the time it runs, the container exists, the content is synchronised, and dependencies are restored. What remains is wiring the workspace together so it is ready for development.
The line with Update-Content Phase is about purpose rather than timing. Update-content reacts to repository content and may rerun when it changes; post-create configures the workspace once, using whatever is now in place.
What is in place when it runs#
Everything. The container, the repository content, and the state the earlier phases prepared are all present — post-create is the only phase that may freely combine them. A hook can link a wrapper from the mounted workspace into a stable path, generate local configuration from checked-in conventions, or install a helper the repository’s own commands expect.
That freedom is also the phase’s discipline. “Everything is available” makes it tempting to place work here that belongs elsewhere; the test is whether the task configures this workspace or provides something reusable. Reusable tooling stays in features no matter how convenient the timing.
Failure behaviour#
A failing post-create hook is reported and skipped, and the container comes
up without that last step of setup. Because post-create is the final phase
of creation, its failure is the most visible: the developer’s first command
often trips over whatever the hook was meant to wire. Rerunning the phase by
hand applies the missing step without rebuilding, which is why post-create
hooks lean on replace-in-place operations such as ln -sfn and cp -f
rather than ones that fail on the second run.
Good uses
- Linking
$WORKSPACE/tools/binto a stable path such as/opt/devcontainer-tools - Configuring shell startup files so container-provided settings reach the preferred shell
- Generating local configuration, such as Terraform defaults derived from repository conventions
Avoid
- Reusable tooling that an available devcontainer feature already provides
- Work that should rerun on every start or editor attach
- Responding to content being created or updated
Examples#
#!/usr/bin/env bash
set -euo pipefail
ln -sfn "$WORKSPACE/tools/bin" /opt/devcontainer-tools
ln -sfn replaces an existing link instead of failing on it, so the hook can be
rerun by hand with run-parts.sh post-create at any time.
This repository’s own post-create hook installs the secrets CLI that
make deploy runs through, guarding so the install happens at most once:
#!/usr/bin/env bash
# The repository's deploy commands run through `secrets exec`, so the dev
# container needs the secrets CLI.
set -euo pipefail
if command -v secrets >/dev/null 2>&1; then
echo "secrets CLI already installed: $(secrets --version 2>/dev/null || true)"
exit 0
fi
curl -fsSL https://git.forge.prosyon.ca/infrastructure/secrets-infra/raw/tag/v3/scripts/install.sh | bash
The command -v guard is the phase’s idempotency in one line: a rerun
reports the installed version and touches nothing.
Connections