DevContainer/Hook
Properties
- alias
- DevContainer Hooks
DevContainer Hooks Conceptual Overview
Overview
- DevContainer hooks are lifecycle entry points that let you run commands at specific moments in the environment's setup, startup, and attachment flow.
- The main distinction is not just which hook exists, but what event it is attached to: host-side preparation, first-time container creation, every container start, or every editor attach.
Context
Key Principles
Hook Families
Before the container exists
During first-time environment creation
During normal runtime
Mechanism
Practical Distinctions
- DevContainer/Hook/onCreateCommand vs DevContainer/Hook/postCreateCommand
- Both are first-creation hooks, but DevContainer/Hook/postCreateCommand is usually the better fit for project setup because it runs after the workspace is mounted and fully available.
- DevContainer/Hook/postStartCommand vs DevContainer/Hook/postAttachCommand
- DevContainer/Hook/postStartCommand is about the container becoming live.
- DevContainer/Hook/postAttachCommand is about a human-facing tool session attaching to that live container.
- DevContainer/Hook/initializeCommand vs everything else
- DevContainer/Hook/initializeCommand is the only standard lifecycle hook in this group that runs on the host rather than inside the container.
- DevContainer/Hook/onCreateCommand vs DevContainer/Hook/postCreateCommand
Mental Model
- A useful way to think about the hooks is:
- DevContainer/Hook/initializeCommand: prepare the inputs
- DevContainer/Hook/onCreateCommand: bootstrap the environment once
- DevContainer/Hook/updateContentCommand: reconcile creation with changing workspace content
- DevContainer/Hook/postCreateCommand: finish project setup
- DevContainer/Hook/postStartCommand: re-establish runtime state
- DevContainer/Hook/postAttachCommand: re-establish developer session state
- A useful way to think about the hooks is:
Misconceptions
- DevContainer/Hook/postCreateCommand and DevContainer/Hook/postStartCommand are interchangeable -> False. One is first-creation setup; the other is every-start behavior.
- DevContainer/Hook/postAttachCommand is a startup hook -> False. It is tied to client attachment, not just container process startup.
- DevContainer/Hook/updateContentCommand is part of every local workflow -> False. It is more relevant in prebuild-oriented workflows than in typical local VS Code usage.
- DevContainer/Hook/initializeCommand can rely on container tools -> False. It runs on the host, before the container exists.
Quick Reference
Hook Where it runs Typical trigger Best fit DevContainer/Hook/initializeCommand Host Recreate or rebuild flow Host-side preparation DevContainer/Hook/onCreateCommand Container First creation only One-time bootstrap DevContainer/Hook/updateContentCommand Container Creation when content changes Prebuild/content reconciliation DevContainer/Hook/postCreateCommand Container First creation only Final project setup DevContainer/Hook/postStartCommand Container Every start Runtime initialization DevContainer/Hook/postAttachCommand Container Every attach Session UX setup
Related