From a192630257a41fbc1d2687426ecb1743cde411b9 Mon Sep 17 00:00:00 2001 From: aevesdocker Date: Mon, 4 Nov 2024 10:46:09 +0000 Subject: [PATCH 1/6] ENGDOCS-2282 --- content/reference/compose-file/services.md | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/content/reference/compose-file/services.md b/content/reference/compose-file/services.md index 24906a00d3df..a38eed6f5403 100644 --- a/content/reference/compose-file/services.md +++ b/content/reference/compose-file/services.md @@ -1505,6 +1505,35 @@ ports: mode: host ``` +## post_start + +`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. + +- `command`: The command to run after the container has started. This attribute is required. +- `user`: The user to run the command. If not set, the command is run with the same user as the main service command. +- `privileged`: Lets the `post_start` command run with privileged access. +- `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. +- `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. + +```yaml +services: + test: + post_start: + - command: ./do_something_on_startup.sh + user: root + privileged: true + environment: + - FOO=BAR +``` + +For more information, see [Use lifecycle hooks](/manuals/compose/how-tos/lifecycle.md). + +## pre_stop + +`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. + +Configuration is equivalent to [`post_start](#post_start). + ### privileged `privileged` configures the service container to run with elevated privileges. Support and actual impacts are platform specific. From c8b100411e71ee234cd57ebd0ee459d4caee6f97 Mon Sep 17 00:00:00 2001 From: aevesdocker Date: Mon, 4 Nov 2024 10:50:00 +0000 Subject: [PATCH 2/6] add link in manuals --- content/manuals/compose/how-tos/lifecycle.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/content/manuals/compose/how-tos/lifecycle.md b/content/manuals/compose/how-tos/lifecycle.md index aa332877e9e3..ee5a8424292c 100644 --- a/content/manuals/compose/how-tos/lifecycle.md +++ b/content/manuals/compose/how-tos/lifecycle.md @@ -63,3 +63,8 @@ services: pre_stop: - command: ./data_flush.sh ``` + +## Reference information + +[`post_start`](/reference/compose-file/services.md#post-start) +[`pre_stop`](/reference/compose-file/services.md#pre-stop) From 21f6ae4b1443c58cec8befede61f02a83505b36f Mon Sep 17 00:00:00 2001 From: aevesdocker Date: Mon, 4 Nov 2024 10:56:30 +0000 Subject: [PATCH 3/6] fix bp --- content/manuals/compose/how-tos/lifecycle.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/manuals/compose/how-tos/lifecycle.md b/content/manuals/compose/how-tos/lifecycle.md index ee5a8424292c..8137ebc60f79 100644 --- a/content/manuals/compose/how-tos/lifecycle.md +++ b/content/manuals/compose/how-tos/lifecycle.md @@ -66,5 +66,5 @@ services: ## Reference information -[`post_start`](/reference/compose-file/services.md#post-start) -[`pre_stop`](/reference/compose-file/services.md#pre-stop) +- [`post_start`](/reference/compose-file/services.md#post-start) +- [`pre_stop`](/reference/compose-file/services.md#pre-stop) From 2d8475d68e2d37a18a00589ff6baab52116118e7 Mon Sep 17 00:00:00 2001 From: aevesdocker Date: Mon, 4 Nov 2024 10:57:08 +0000 Subject: [PATCH 4/6] fix bp --- content/manuals/compose/how-tos/lifecycle.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/manuals/compose/how-tos/lifecycle.md b/content/manuals/compose/how-tos/lifecycle.md index 8137ebc60f79..b906cc29d08e 100644 --- a/content/manuals/compose/how-tos/lifecycle.md +++ b/content/manuals/compose/how-tos/lifecycle.md @@ -66,5 +66,5 @@ services: ## Reference information -- [`post_start`](/reference/compose-file/services.md#post-start) -- [`pre_stop`](/reference/compose-file/services.md#pre-stop) +- [`post_start`](/reference/compose-file/services.md#post_start) +- [`pre_stop`](/reference/compose-file/services.md#pre_stop) From 1726789c93f4a04ccf33ff9ec9eca830873dca72 Mon Sep 17 00:00:00 2001 From: aevesdocker Date: Tue, 5 Nov 2024 09:05:38 +0000 Subject: [PATCH 5/6] ENGDOCS-2282 --- content/manuals/compose/how-tos/lifecycle.md | 2 ++ content/reference/compose-file/services.md | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/content/manuals/compose/how-tos/lifecycle.md b/content/manuals/compose/how-tos/lifecycle.md index b906cc29d08e..d044f1bed13d 100644 --- a/content/manuals/compose/how-tos/lifecycle.md +++ b/content/manuals/compose/how-tos/lifecycle.md @@ -6,6 +6,8 @@ desription: How to use lifecycle hooks with Docker Compose keywords: cli, compose, lifecycle, hooks reference --- +{{< introduced compose 2.30.0 "../releases/release-notes.md#2300" >}} + ## Services lifecycle hooks When Docker Compose runs a container, it uses two elements, diff --git a/content/reference/compose-file/services.md b/content/reference/compose-file/services.md index a38eed6f5403..0fc38a501f72 100644 --- a/content/reference/compose-file/services.md +++ b/content/reference/compose-file/services.md @@ -1507,9 +1507,11 @@ ports: ## post_start +{{< introduced compose 2.30.0 "../../manuals/compose/releases/release-notes.md#2300" >}} + `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. -- `command`: The command to run after the container has started. This attribute is required. +- `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. - `user`: The user to run the command. If not set, the command is run with the same user as the main service command. - `privileged`: Lets the `post_start` command run with privileged access. - `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. From 7007a7691889d56ed43e2d602a689c7f18310fb3 Mon Sep 17 00:00:00 2001 From: aevesdocker Date: Tue, 5 Nov 2024 09:05:56 +0000 Subject: [PATCH 6/6] ENGDOCS-2282 --- content/reference/compose-file/services.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/content/reference/compose-file/services.md b/content/reference/compose-file/services.md index 0fc38a501f72..798b3ad69e3e 100644 --- a/content/reference/compose-file/services.md +++ b/content/reference/compose-file/services.md @@ -1532,6 +1532,8 @@ For more information, see [Use lifecycle hooks](/manuals/compose/how-tos/lifecyc ## pre_stop +{{< introduced compose 2.30.0 "../../manuals/compose/releases/release-notes.md#2300" >}} + `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. Configuration is equivalent to [`post_start](#post_start).