← All notes

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

Sources

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

Permanent ID: iil:note:gpm1hm7z

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.},
}

Markdown

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.

All artifact files (JSON index)

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.