Run a database migration command when deploying a Docker container to AWS Run a database migration command when deploying a Docker container to AWS docker docker

Run a database migration command when deploying a Docker container to AWS


You need create entrypoint. This script runs at the container startup.

entrypoint.sh file:

#create or update db./waitforit.sh <DB_HOST>:<DP_PORT> -t 30php app/console doctrine:migrations:execute # start apacheapache2-foreground

wait for it it is a script waited when database is started up


Just leaving this here for the next one that searches for this... ;-)

When using a recent version of Doctrine, there is a pretty handy parameter for this:

php bin/console doctrine:migrations:migrate --no-interaction --allow-no-migration

The "allow-no-migration" parameter instructs doctrine not to throw an exception, when there is nothing to do...


I do as follows:

docker-compose exec [containerID] ./app/console migrations:migrate --no-interaction