Reputation: 113
I have a big static database where no data is inserted / updated.
I created a Dockerfile in the following manner which works well to create the database in the docker container. There are a bunch of insert .sql scripts in data/ which populates the database.
FROM mysql:5.7
ADD data/* /docker-entrypoint-initdb.d/
EXPOSE 3306
The only problem with this is that it takes a long time to start up, so I ran the container locally and adjusted it slightly so that the data persisted within the container, and I removed the startup scripts from the startup script directory. I then committed this container to a new docker image (committed-image:v1
).
This worked, however the only problem I have is that the password for the mysql root user for this database is fixed to the password which I used when I committed the image.
My question is: Is there any way to run another startup script on top of this new image (which already has an existing database)? I need to modify the password of the root user to match an environment variable in the container (cant use MYSQL_ROOT_PASSWORD
now since the startup script no longer runs in the container spun up from the new committed image).
Upvotes: 0
Views: 321
Reputation: 14666
The trouble is your entrypoint script for mysql:5.7 (the default) is quite elaborate. DATABASE_ALREADY_EXISTS is based on the existence of the mysql/database directory and therefore the ROOT doesn't get reinitialized. Its hard to get a loaded database to exist without a system tables include a root user being set.
Solutions:
a) the default configuration of mysql instance isn't particularly conducive to large database loads. Including a configuration item that sets innodb_buffer_pool_size to several gig of ram/80% of available RAM will help the load and run.
and/or:
b) set innodb_file_per_table=1 in the configuration and then for your SQL, use CREATE TABLESPACE / ALTER TABLE .. TABLESPACE =
to load the data from a pre-geneated idb file. See these instructions from the manual on extracting a tablespace.
To create/set configuration file settings see the readme notes from dockerhub. You could also just drop in a file like /etc/mysql/conf.d/config-file.cnf
in your Dockerfile.
Upvotes: 1