Why isn't my docker-entrypoint-initdb.d script (as specified in docker-compose.yml) executed to initialize a fresh MySQL instance? Why isn't my docker-entrypoint-initdb.d script (as specified in docker-compose.yml) executed to initialize a fresh MySQL instance? docker docker

Why isn't my docker-entrypoint-initdb.d script (as specified in docker-compose.yml) executed to initialize a fresh MySQL instance?


Devil hides in details...

You have a double definition of root in your env vars. root user is created by default with password from MYSQL_ROOT_PASSWORD. You then ask to create a second "normal" user... with the exact same name and password (i.e. with MYSQL_USER and MYSQL_PASSWORD)

If you look carefully at your startup log, you will see an error

db_1       | ERROR 1396 (HY000) at line 1: Operation CREATE USER failed for 'root'@'%'

This actually stops further processing of your init files in docker-entrypoint-initdb.d and goes on with the rest of the image startup process (i.e. restarting mysql after initialization on temporary server).

Simply drop MYSQL_USER and MYSQL_PASSWORD in your env vars, or set a different user than root and you will immediately see your init files processed (don't forget to empty your data dir again).