Docker Compose supports pre_start service lifecycle hooks
Introduced 2026-07-02 · score 0.91
HOW TO USE IT
When a service needs initialization before it starts, configure its `pre_start` hook. Run `docker compose up` to start the application; each hook step runs in an ephemeral container and a non-zero exit prevents the service from starting.
services:
app:
image: <service-image>
pre_start:
- command: <initialization-command>
docker compose upWHY THIS HELPS
Run a service initialization hook before starting its containers in a Compose application.
REQUIREMENTS AND LIMITATIONS
- Version: v5.3.0
- services.<service>.pre_start: Sequence of init-container steps that run before the service container starts.
- pre_start[].command: Command to run; optional if the image entrypoint already runs the intended command.
- pre_start[].image: Image for the ephemeral container; defaults to the parent service image.
- pre_start[].user: Command user; defaults to the image user, or the service command user if `image` is omitted.
- pre_start[].privileged: Whether the hook command runs with privileged access.
- pre_start[].working_dir: Hook working directory; defaults to the service command working directory.
- pre_start[].environment: Environment values for the hook; inherits the service command environment and can append or override values.
- pre_start[].per_replica: Set `false` to run once for the service before any replica starts.
- Prerequisite: Requires Docker Compose 5.3.0 or later.
- The hook runs once per service, only when no replica is already running.
FIRST-PARTY EVIDENCE
- https://github.com/docker/compose/releases/tag/v5.3.0
- https://github.com/docker/compose/pull/13862
- https://docs.docker.com/reference/compose-file/services/
Check the installed version and the source before using it. Entry JSON