You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/reference/compose-file/services.md
+29Lines changed: 29 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1505,6 +1505,35 @@ ports:
1505
1505
mode: host
1506
1506
```
1507
1507
1508
+
## post_start
1509
+
1510
+
`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.
1511
+
1512
+
- `command`: The command to run after the container has started. This attribute is required.
1513
+
- `user`: The user to run the command. If not set, the command is run with the same user as the main service command.
1514
+
- `privileged`: Lets the `post_start` command run with privileged access.
1515
+
- `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.
1516
+
- `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.
1517
+
1518
+
```yaml
1519
+
services:
1520
+
test:
1521
+
post_start:
1522
+
- command: ./do_something_on_startup.sh
1523
+
user: root
1524
+
privileged: true
1525
+
environment:
1526
+
- FOO=BAR
1527
+
```
1528
+
1529
+
For more information, see [Use lifecycle hooks](/manuals/compose/how-tos/lifecycle.md).
1530
+
1531
+
## pre_stop
1532
+
1533
+
`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.
1534
+
1535
+
Configuration is equivalent to [`post_start](#post_start).
1536
+
1508
1537
### privileged
1509
1538
1510
1539
`privileged`configures the service container to run with elevated privileges. Support and actual impacts are platform specific.
0 commit comments