Example Devfile v2 showing how to run an init container
in an Eclipse Che / DevWorkspace workspace that writes to .bash_profile before
the main dev container starts.
Devfile v2 doesn't have a native initContainer component type, but the
preStart lifecycle event turns an apply command bound to a container
component into an init container in the workspace pod. Init containers listed
under preStart run in order, before any of the workspace's main containers
start.
For the init container's changes to be visible in your shell, it needs to
write to a location that's also mounted into the main dev container — so this
example defines a shared volume component mounted at /home/user in both
containers.
home— avolumecomponent shared between the init and dev containers.tools— the main dev container (universal-developer-image), withhomemounted at/home/user.init-bash-profile— a minimal (ubi8-minimal) container that appends an alias and an env var export to/home/user/.bash_profile. Because it's only referenced via thepreStartevent (never a workspace command a user runs), it's realized as an init container rather than a long-running container.
commands:
- id: init-bash-profile-cmd
apply:
component: init-bash-profile
events:
preStart:
- init-bash-profile-cmdThe apply command references the init-bash-profile component, and
events.preStart lists it — this is what tells the DevWorkspace Operator to
run it as an init container ahead of the workspace's regular containers.
Edit the args in the init-bash-profile component to add whatever you need
in .bash_profile (aliases, exports, sourcing other scripts, etc.). Multiple
commands can be listed under preStart; they run as sequential init
containers in the order given.
applycommands used inpreStartmust referencecontainercomponents, not plugins.- The init and main containers must mount the shared volume at the same path, or the shell won't see the file where it expects it.
postStartis a related but different event — it runs anexeccommand inside an already-running container rather than as a separate init container.