[Fixed]-Dockerize does not delay the container initialization

1👍

When your Postgres container is up it starts to receive tcp packages you send with the command: dockerize -wait tcp://sakahama_db:5432 , but it does not mean that the Postgres service is ready. It takes some time to load, to set up users, passwords, create the db or load the databases and make all the grants needed.

I had a similar issue with Flask and MySQL, I created an sh script like you did and inside it I made a simple loop to check if the service was up before starting the Flask application

I am not a shell script Senior but here follow the script:

# testing if databas is up
mysql -h database -uroot -proot databasename
ISDBUP=$?
while [[ $ISDBUP != "0" ]]; do
    echo "database is not up yet, waiting for 5 seconds"
    sleep 5;
    mysql -h database -uroot -proot databasename -e "SELECT 1;";
    ISDBUP=$?
done

# starting the application
python server.py app
👤wsilva

Leave a comment