Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

depends_on post_start_completed_successfully #12279

Closed
stormshield-gt opened this issue Nov 11, 2024 · 3 comments
Closed

depends_on post_start_completed_successfully #12279

stormshield-gt opened this issue Nov 11, 2024 · 3 comments

Comments

@stormshield-gt
Copy link

Description

Since #12166 we have the post_start hook. A use case I have for this is to run some initialization code after the container starts. It will be great that other services than depend on the initialization code only start when it's completed successfully.
I don't know if it's planned but maybe we could have something like this:

depends_on:
  db:
    condition: post_start_completed_successfully
@stormshield-gt stormshield-gt changed the title depends_on post_start_completed_successfully depends_on post_start_completed_successfully Nov 11, 2024
@idsulik
Copy link
Collaborator

idsulik commented Nov 11, 2024

It will be great that other services than depend on the initialization code only start when it's completed successfully.

it should work in this way not).

services:
  app1:
    image: alpine
    command: echo 'app1 is completed'
    depends_on:
      - app2
  app2:
      image: alpine
      command: ["sh", "-c", "sleep 10 && echo 'app2 is completed'"]
      post_start:
        - command: ["sh", "-c", "sleep 5 && echo 'app2 post start hook executed'"]

output:

[+] Running 2/0
 ✔ Container tmp-app2-1  Created                                                                                                                                                                                                0.0s 
 ✔ Container tmp-app1-1  Created                                                                                                                                                                                                0.0s 
Attaching to app1-1, app2-1
app2-1 ->  | app2 post start hook executed
app1-1     | app1 is completed
app1-1 exited with code 0
app2-1     | app2 is completed
app2-1 exited with code 0

@ndeloof
Copy link
Contributor

ndeloof commented Nov 11, 2024

Indeed, until there's a bug in our codebase, dependent service should only start after post_start hooks have been ran.

@ndeloof
Copy link
Contributor

ndeloof commented Nov 12, 2024

Closing issue, please comment or open a new issue if you have more context to share on this

@ndeloof ndeloof closed this as completed Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants