Closed krissss closed 7 years ago
I think of two ways:
php yii migrate
command in dockerfile, but this method needs to use external network 3306 port. (feasible but not safe)You can not use yii migrate
in the Dockerfile
since each step in the build process is completely isolated. Therefore you also do not have a running database in any step, besides the fact that it should be a separate container anyway.
We usually use a custom startup command in production, like so
command: "sh -c 'yii migrate --interactive=0 && docker-run.sh'"
Btw: with docker-compose v2
syntax you do not need to link the db container anymore.
Checkout dmstr/phd5 for a dockerized Yii2 app template with database.
I find a solution: in ENTRYPOINT
like docker-entrypoint.sh
if [ ${YII_MIGRATION_DO} == 1 ]; then
if [ ! -d "/yii2-migrat-flag" ]; then
php yii migrate --interactive=0
mkdir /yii2-migrat-flag
fi
fi
you can modify ENV
YII_MIGRATION_DO
in Dockerfile
to change is need to do that
I've been running Yii migrate manually, but how can I configure dockerfile or docker-compose to do it automatically? DB is another container.