According to Controlling startup order in Compose, one can control the order in which Docker Compose starts containers by using a \"wait-for-it\" script. Script wait-for-it.sh
However, if one uses this option, the container will no longer run its default
ENTRYPOINT
orCMD
command becauseentrypoint:
overrides the default.
That is expected, which is why the wait-for-it is presented as a wrapper script.
It does allow to execute a "subcommand" though:
wait-for-it.sh host:port [-s] [-t timeout] [-- command args]
^^^^^^^^^^^^
The subcommand will be executed regardless if the service is up or not.
If you wish to execute the subcommand only if the service is up, add the--strict
argument.
That means the CMD
part of your image can be used for your actual container command, as its parameters will passed in parameters to the ENTRYPOINT
command:
entrypoint: wait-for-it.sh host:port --
cmd: mycmd myargs
This should work... except for docker-compose issue 3140 (mentioned by the OP Derek Mahar in the comments)
entrypoint defined in
docker-compose.yml
wipes outCMD
defined in Dockerfile
That issue suggests (Jan. 2021)
If you have a custom image you can add a startscript to the build and call it inside the dockerfile and in the
docker-compose
you can call it again.
Thats a way to avoid duplicate for more complicated entrypoints.