Run Dev Container lifecycle commands at create and start
Answer: When you create or work with a dev container, different commands may need to run at different points in its lifecycle. Each command property is a string or list of command arguments that should execute from the workspaceFolder. A single-string value is run in /bin/sh. Put && in that string to execute multiple commands. The array syntax will execute the command without a shell.
The devcontainers CLI documents devcontainer run-user-commands. That command runs lifecycle commands like postCreateCommand.
Create, start, and attach
initializeCommand runs on the host machine. It runs during initialization, during container creation, and on subsequent starts. It may run more than once during a given session. onCreateCommand will run after initializeCommand. It is the first of three commands — the others are updateContentCommand and postCreateCommand — that finalizes container setup when a new dev container is created. Those commands execute inside the container immediately after it has started for the first time.
postStartCommand is a command to run each time the container is successfully started. postAttachCommand is a command to run each time a tool has successfully attached to the container. waitFor is an enum that specifies the command any tool should wait for before connecting. It defaults to updateContentCommand.
| Property | Description | |---|---| | initializeCommand | host machine | | onCreateCommand | inside the container | | updateContentCommand | after onCreateCommand | | postCreateCommand | after updateContentCommand | | postStartCommand | each time the container is successfully started | | postAttachCommand | each time a tool has successfully attached | | waitFor | updateContentCommand |
See also
Claims
- id: C1 claim: onCreateCommand runs after initializeCommand, and the create-time trio finishes with postCreateCommand. source: S1 evidence: "
onCreateCommandwill run afterinitializeCommand"
- id: C2 claim: postStartCommand runs on each successful start, and waitFor defaults to updateContentCommand. source: S1 evidence: "Defaults to
updateContentCommand."
- id: C3 claim: The devcontainer CLI run-user-commands action runs lifecycle commands such as postCreateCommand. source: S2 evidence: "Runs lifecycle commands like
postCreateCommand"
Sources
- [S1] devcontainer.json reference. Dev Container Specification. https://containers.dev/implementors/json_reference/ . License: CC-BY-4.0. Accessed 2026-11-19.
- [S2] devcontainers/cli README. devcontainers/cli. https://raw.githubusercontent.com/devcontainers/cli/main/README.md . License: MIT. Accessed 2026-11-19.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Dev Container Specification, devcontainer.json reference; devcontainers/cli, devcontainers/cli README. CC-BY-4.0; MIT. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Dev Container Specification, devcontainer.json reference; devcontainers/cli, devcontainers/cli README. CC-BY-4.0; MIT.
Cite this
iinventedlight. 2026. "Run Dev Container lifecycle commands at create and start." iinventedlight Library, iil:note:gpm1hm7z, version of 2026-11-19. https://iinventedlight.com/library/notes/devcontainer-lifecycle/. License: CC-BY-4.0.
@misc{iil_note_gpm1hm7z,
author = {{iinventedlight}},
title = {{Run Dev Container lifecycle commands at create and start}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-19},
url = {https://iinventedlight.com/library/notes/devcontainer-lifecycle/},
note = {Permanent ID iil:note:gpm1hm7z. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- devcontainer-lifecycle.table.json (table; CC-BY-4.0)
- devcontainer-lifecycle.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/devcontainer-lifecycle.md.