With the Docker image of mysql you can put in mysqldump scripts into a specific folder and it will use those scripts to load up an empty data on first start up.
What I was wondering is how to create an image where that execution had already taken place as part of the build so we don't have to wait for the initial data load.
The purpose of the image is to have a developer copy of a database for local testing.
If possible I would like it to be done as a multistage Docker build so I can build it without having MySQL installed on the build server.
My general thought process though I haven't tried it out yet is as follows:
FROM mysql as builder COPY *.sql /somefolder COPY buildscript.sh /buildscript.sh FROM mysql COPY --from build /var/lib/mysql /data # to avoid using the volume folder And buildscript.sh does something like
- start up mysqld
- wait for the mysqld to fully start up (??)
- run the SQLs used to build the data
- shut down mysqld
- sync (make sure all the files are written)