How can I make my Docker compose “wait-for-it” script invoke the original container ENTRYPOINT or CMD?

后端 未结 1 714
花落未央
花落未央 2021-02-07 00:28

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

相关标签:
1条回答
  • 2021-02-07 00:51

    However, if one uses this option, the container will no longer run its default ENTRYPOINT or CMD command because entrypoint: 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 out CMD 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.

    0 讨论(0)
提交回复
热议问题