Skip to content

Commit 66d0b99

Browse files
authored
Engdocs 2282 (#21326)
<!--Delete sections as needed --> ## Description Add lifecycle attributes to the compose spec ## Related issues or tickets <!-- Related issues, pull requests, or Jira tickets --> ## Reviews <!-- Notes for reviewers here --> <!-- List applicable reviews (optionally @tag reviewers) --> - [ ] Technical review - [x] Editorial review - [ ] Product review
1 parent 7b1deed commit 66d0b99

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

content/manuals/compose/how-tos/lifecycle.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ desription: How to use lifecycle hooks with Docker Compose
66
keywords: cli, compose, lifecycle, hooks reference
77
---
88

9+
{{< introduced compose 2.30.0 "../releases/release-notes.md#2300" >}}
10+
911
## Services lifecycle hooks
1012

1113
When Docker Compose runs a container, it uses two elements,
@@ -63,3 +65,8 @@ services:
6365
pre_stop:
6466
- command: ./data_flush.sh
6567
```
68+
69+
## Reference information
70+
71+
- [`post_start`](/reference/compose-file/services.md#post_start)
72+
- [`pre_stop`](/reference/compose-file/services.md#pre_stop)

content/reference/compose-file/services.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,39 @@ ports:
15051505
mode: host
15061506
```
15071507

1508+
## post_start
1509+
1510+
{{< introduced compose 2.30.0 "../../manuals/compose/releases/release-notes.md#2300" >}}
1511+
1512+
`post_start` defines a sequence of lifecycle hooks to run after a container has started. The exact timing of when the command is run is not guaranteed.
1513+
1514+
- `command`: Specifies the command to run once the container starts. This attribute is required, and you can choose to use either the shell form or the exec form.
1515+
- `user`: The user to run the command. If not set, the command is run with the same user as the main service command.
1516+
- `privileged`: Lets the `post_start` command run with privileged access.
1517+
- `working_dir`: The working directory in which to run the command. If not set, it is run in the same working directory as the main service command.
1518+
- `environment`: Sets environment variables specifically for the `post_start` command. While the command inherits the environment variables defined for the service’s main command, this section lets you add new variables or override existing ones.
1519+
1520+
```yaml
1521+
services:
1522+
test:
1523+
post_start:
1524+
- command: ./do_something_on_startup.sh
1525+
user: root
1526+
privileged: true
1527+
environment:
1528+
- FOO=BAR
1529+
```
1530+
1531+
For more information, see [Use lifecycle hooks](/manuals/compose/how-tos/lifecycle.md).
1532+
1533+
## pre_stop
1534+
1535+
{{< introduced compose 2.30.0 "../../manuals/compose/releases/release-notes.md#2300" >}}
1536+
1537+
`pre_stop` defines a sequence of lifecycle hooks to run before the container is stopped. These hooks won't run if the container stops by itself or is terminated suddenly.
1538+
1539+
Configuration is equivalent to [`post_start](#post_start).
1540+
15081541
### privileged
15091542

15101543
`privileged` configures the service container to run with elevated privileges. Support and actual impacts are platform specific.

0 commit comments

Comments
 (0)