I am dockerizing an application with two services in docker-compose.yml: a web image build from php:7.3.28-apache and a database image build from postgres:11.12-alpine. Inside database Dockerfile I am executing a sql file to populate the database by doing:
COPY ./dump.sql /docker-entrypoint-initdb.d/
In my web image I do a migration. But the migration should only occur after the database end executing the sql file. So I use the wait-for-it.sh script to wait for the database port to be available:
CMD composer install ; wait-for-it -t 0 db:5432 -- bin/console doctrine:migrations:migrate ; apache2-foreground
The problem is that the port db:5432 becomes available before dump.sql file end execution.
I already tried
depends_on:
- db
in docker-compose.yml and the problem persists. Is there a way to lock the port db:5432 until dump is done, or a way to make web service to wait for the end of dump execution in db service?