I am trying to create a MySQL Docker container that is preconfigured with a specific schema and seed data so that I can connect other containers to it in the form of db. I use the dockerfile / mysql trusted file as the base, and I wrote a Docker file to create a new image from this base and add my .sql schema to it. After creating this image (mysql: base), I try to run bash in a new container, then go into mysql and create my database and then import the schema. Then I exit the container and try to pass the container to a new Docker sample. However, the resulting image does not save any changes that I made to MySQL db. It saves other files that I wrote in the container, but not db.
Here is the Docker file that I use to create the original image (myorg / mysql: base).
FROM dockerfile/mysql:latest MAINTAINER (me) ADD schema.sql /data/schema.sql EXPOSE 3306
After that, I look into the image:
docker run -i -t myorg/mysql:base bash
And start MySQL to import the schema:
myslqd_safe & 141218 00:15:56 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql mysql -u root mysql> CREATE DATABASE mydb; exit; mysql -u root -D mydb < schema.sql
I can enter mysql and verify that the schema has been imported successfully:
mysql -u root -D mydb -e "SELECT * from tokens;"
Also, if I go to /var/lib/mysql
, I see that there is a mydb
directory containing the .frm files corresponding to db.
But when I go out and try to pass this container to a new image:
docker commit -m="import schema.sql" -a="Me" 72c2ff39dd65 myorg/mysql:seed
And then go to the new image:
docker run -i -t --rm myorg/mysql:seed bash
The db files are no longer in / var / lib / mysql, and starting mysql -u root -e "SHOW DATABASES"
does not show the mydb
database, but only the default values mysql
, information_schema
and performance_schema
dbs. I found that if I create a new text file in the container ( echo 'test' > newfile
), this file will be present in the captured image, but not in db.
I wonder if this is because the Dockerfile with the trusted image has VOLUME ["/etc/mysql", "/var/lib/mysql"]
, so it mounts the db directory as the volume. My Dockerfile does not have this command, but I donโt know if it inherited it anyway (I donโt quite understand how the volumes work well enough to know how this might affect my build). I donโt need db installed as one because I need another container to connect to it over a network connection (for this I use docker links).
FWIW, I am running boot2docker 1.3.2 on OS X 10.9.5.