docker-compose mysql init sql is not executed docker-compose mysql init sql is not executed docker docker

docker-compose mysql init sql is not executed


The docker-entrypoint-initdb.d folder will only be run once while the container is created (instantiated) so you actually have to do a docker-compose down -v to re-activate this for the next run.

If you want to be able to add sql files at any moment you can look here at a specialized MySql docker image... http://ivo2u.nl/o4


Many containerized applications, especially stateful ones, have a way of running init scripts (like the sql scripts here) and they are supposed to run only once.

And since they are stateful, the volumes are a source of truth for the containers on whether to run the init scripts or not on container restart.

Like in your case, deleting the folder used for bind mount or using a new named volume should re-run any init scripts present.


These scripts run when you create the container, not every time you start it.

You can docker-compose up --force-recreate mysql to force those scripts to re-run.

Additionally, if you have a volume like this ./db_data:/var/lib/mysql:rw, then you also need to remove ./db_data before recreating the container.

I'm not a docker expert, but this worked for me.