The right way to execute wait-for-it script in docker-compose

I have a wait-for-itscript added to my docker file and I am executing it in my docker. It works great with this setting:

In docker-compose:

entrypoint: ./wait-for-it.sh mysql

wait-for-it script:

...checks
>&2 echo "MySQL is up - executing command"
exec ../../../entrypoint.sh npm start

the output of the command when I execute docker ps:

COMMAND
"./wait-for-it.sh ..." 

This works great, but I don't like the "setup". I want it to execute wait-for-it.sh, and if it succeeds, I want to go to ENTRYPOINT+ the of CMDmy docker file. I don't want to run my hardcode entry point from my wait-for-it.sh

So, I changed my wait-for-it.sh script:

>&2 echo "MySQL is up - executing command"
exec "$@"

Inside my docker file, I have:

ENTRYPOINT ["/entrypoint.sh"]

EXPOSE 2368
CMD ["npm", "start"]

How should my docker-compose.yaml look like this to execute it correctly after executing my wait-for-it script?

, , docker ps:

COMMAND
"/entrypoint.sh np..."

- docker-compose.yaml, :

  entrypoint: ./wait-for-it.sh mysql  /entrypoint.sh
  command: ["npm", "start"]
+4
1

script :

#!/usr/bin/env bash

while true; do 
    if which "$1" >/dev/null; then
        echo exists
        break
    else
        echo does not exist
        // sleep 3 seconds
        sleep 3
    fi
done
-1

Source: https://habr.com/ru/post/1670719/


All Articles