Description
Problem
I found postgres image can't block dependent startup, which make dependent start up too early.
Actual
If dependent accept client at early time, dependent failed.
Expected
After postgres ready, dependent should not startup and accept client.
Try
I found .depends_on.X.condition works, but not very graceful to solve wait-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.
foo:
...
depends_on:
bar:
condition: service_healthy
...
bar:
...
tmpfs:
- /tmp
healthcheck:
test: 'if [ -e /tmp/first_run ]; then sleep 24h; else touch /tmp/first_run; bash /script/wait.sh; fi'
timeout: 25h
interval: 1s
Feat
Above workaround I still don't think very ideal, so I opened a feat.
Enhance healthcheck behavior like lifecyle.
foo:
...
depends_on:
bar:
condition: service_lifecycle_bootstrap
...
bar:
...
lifecycle:
bootstrap: 'bash /script/wait.sh'
Related
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
Description
Problem
I found
postgresimage can't block dependent startup, which makedependentstart up too early.Actual
If
dependentacceptclientat early time,dependentfailed.Expected
After
postgresready,dependentshould 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.conditionworks, but not very graceful to solvewait-for-container-x-before-starting-y.If
.intervalbig, run.healthcheck.testlate, startdependentlate, not very ideal.If
.intervalsmall, run.healthcheck.testtoo 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
healthcheckbehavior like lifecyle.Related
Execute a command after run #1809
Proposal: docker-compose events #1510
Additional
Are there lifecyle support within container ecosystem?
Yes, vscode
devcontainersupport lifecycle.https://github.com/devcontainers/spec/blob/main/schemas/devContainerFeature.schema.json#L106-L206
initializeCommandonCreateCommandupdateContentCommandpostCreateCommandpostStartCommandpostAttachCommand