How to make docker wait for SQL script inside /docker-entrypoint-initdb.d to be executed How to make docker wait for SQL script inside /docker-entrypoint-initdb.d to be executed docker docker

How to make docker wait for SQL script inside /docker-entrypoint-initdb.d to be executed


Solution is to utilise HEALTHCHECK [OPTIONS] CMD command

The command after the CMD keyword can be either a shell command (e.g. HEALTHCHECK CMD /bin/check-running) or an exec array (as with other Dockerfile commands; see e.g. ENTRYPOINT for details).

The command’s exit status indicates the health status of the container. The possible values are:

0: success - the container is healthy and ready for use

1: unhealthy - the container is not working correctly

2: reserved - do not use this exit code

Probably you can create some shell script

#!/bin/sh# if your last table exists we assume may be # we are now ready for migration # put whatever logic you have to ensure data import was successful# if file exits then exit code 0 else exit code 1[ -f  "/path/to/my/last/table" ] && exit 0 || exit 1

In docker-compose.yml you need

depends_on:      database:           condition: service_healthy