I found out about the /docker-entrypoint-initdb.d
directory from this answer, and also read the "Initializing a fresh instance" section of the "How to use this image" MySQL documentation. But when I run docker-compose up
in the directory containing the docker-compose.yml
file below, my database isn't initialized.
services:
# Use root/root as MySQL user/password credentials
db:
image: mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: root
MYSQL_PASSWORD: root
MYSQL_DATABASE: db
volumes:
- ./mysql/data:/var/lib/mysql
- ./mysql/init:/docker-entrypoint-initdb.d/:ro
adminer:
image: adminer
restart: always
ports:
- 8080:8080
I confirmed the ./mysql/init
directory contains a file named init.sql
. And I confirmed that after I empty the ./mysql/data
directory and run docker-compose up
, that a db
database is created. But the database is not populated, unless I manually execute the script in Adminer. (I click on "Import", then choose the file and press the Execute button.)
I looked for messages in the console output after running docker-compose up
that indicate an attempt to run init.sql
and can't find anything.
Update: The MySQL version is 8.0.19.