-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Enhance healthcheck
blocking dependent
behavior like lifecyle
#10580
Comments
healthcheck
behavior like lifecylehealthcheck
blocking dependent
behavior like lifecyle
the devcontainer feature you're listing here is about command hooks to run during container lifecycle, not about dependency management. IIUC your needs, you have to wait for healthcheck interval and health status unfortunately is managed by container runtime, not docker compose, so we can't tweak the interval to avoid unnecessary runs once service is started |
I've worked around this like so postgres: &postgres
image: postgres:16
healthcheck:
test:
- "CMD"
- "bash"
- "-c"
- "echo 'select 1' | psql --dbname='postgres' --username=postgres"
# Runs the healthcheck every 12 hours. We don't particularly want this, but we are forced to specify *some*
# interval.
interval: 12h
timeout: 10s
retries: 3
# This is what we really care about -- it amends the "interval" above, by running the health check every second,
# stopping after 10 seconds, or if the test succeeds, whichever comes first. The docker docs are not clear about
# this.
start_period: 10s
start_interval: 1s |
Thanks. I read what docs I could find but it's not obvious that this new feature solves the problem in this issue. I assume it does, otherwise you wouldn't have drawn my attention to it. But might the docs for this new feature give an example of it solving this problem? Or at least mention that it can solve this class of problem? |
What you are looking for is |
Yes, my workaround above uses that. |
Description
Problem
I found
postgres
image can't block dependent startup, which makedependent
start up too early.Actual
If
dependent
acceptclient
at early time,dependent
failed.Expected
After
postgres
ready,dependent
should not startup and acceptclient
.Try
Add
/docker-entrypoint-initdb.d/wait.sh
, which does not block dependent.Overwrite command, which does not block dependent.
Besides, when overwrite entry/command, sometimes you may need to know what is the original entry/command, and call these HARD CODED command in a very ugly way.
https://stackoverflow.com/questions/31746182/docker-compose-wait-for-container-x-before-starting-y
I found
.depends_on.X.condition
works, but not very graceful to solvewait-for-container-x-before-starting-y
.If
.interval
big, run.healthcheck.test
late, startdependent
late, not very ideal.If
.interval
small, run.healthcheck.test
too many times, not very graceful.Workaround
Below is my workaround.
Feat
Above workaround I still don't think very ideal, so I opened a feat.
Enhance
healthcheck
behavior like lifecyle.Related
Execute a command after run #1809
Proposal: docker-compose events #1510
Additional
Are there lifecyle support within container ecosystem?
Yes, vscode
devcontainer
support lifecycle.https://github.com/devcontainers/spec/blob/main/schemas/devContainerFeature.schema.json#L106-L206
initializeCommand
onCreateCommand
updateContentCommand
postCreateCommand
postStartCommand
postAttachCommand
The text was updated successfully, but these errors were encountered: