Hi, I am trying to introduce starting conditions for containers, so that they wait for each other before starting. I am currently doing this with healthchecks.
We’ll open an internal issue for this. In the meantime, the Docker documentation has some hints how to use a bit of extra tooling to replicate that behaviour, if I read it well.
Let us know if you tried it out, and whether it works…
Hi @imrehg, thanks for you answer! I did indeed used some wrapper scripts to delay the start of containers, after the example of wait-for-*
command: wait-for-container1.sh start-container2
With the healthcheck option I would still have a script executing, maybe it is also a bit more transparent. So looking forward to seeing it supported in the future.
The healthcheck option is nice but it does not do anything if another service cannot depend on it. I have had the case where a service only exists to expose kernel modules and in this case a simple file written to the filesystem of that service is enough to say “I am done” and therefore having a script running on services that depend on that does not work since they cannot look inside the dependant service filesystem.
I honestly think that we are missing a proper way of a service depending on the healthcheck of another services
I meant services which are doing something like insmod to make kernel modules available to other services however what you have described is another setup.
In your example service one could be a service which exposes some files required by service two. This means service two depends on service onebeing done.
So in the setup you described service one and two will come up at the same time which might not work. Using depends_on can help however balena only waits for the container to start while service one can take some time to be finished with making those files available.
This is what the condition part of depends_on is solving which we are missing today in Balena
The condition form of depends_on is removed in version 3 of docker-compose. Will an alternative method work for you like the ones explained in https://docs.docker.com/compose/startup-order/?
Yeah I noticed it was removed in version 3 sadly. Has no replacement been specified? I saw just yesterday that docker has recently published official specs for the docker compose so maybe something can be used from there.
An alternative method would of course suit us however the alternative method you linked requires that the container which depends on some service to have a way to ask the dependant service whether it is done doing what needs to be done. In the cases where the dependant service does not expose an external API for that it does not work.
This is why the healthcheck is a good option as it exposes an external API to docker compose that other servicers can query on so the service does not have to do this.
While it would be possible to expose something for other service to query for a dependency, there’s some elegance in providing that on a docker compose level so underlying services don’t have to implement that themselves
Hey there! I totally get your concerns. We’ve talked about leveraging the healthcheck (https://docs.docker.com/compose/compose-file/#healthcheck) options in combination with the depends_on option accomplish this, but its not something that’s in place right now (or will be for sure)