I apologize for this long answer, but you have a little way to get to where you want. I will say that, as a rule, you would not put the storage for the database in the same container as the database itself, you would either mount the host volume so that the data would be stored on the docker host, or perhaps the container could be used to hold data (/ var / lib / mysql). Also, I am new to mysql, so this may not be very efficient. However...
I think there may be several problems. A Docker file is used to create an image. You need to complete the build step. At a minimum, from the directory containing the Dockerfile, you will do something like:
docker build .
Dockerfile describes the created image. I am not very good at mysql (I'm a fan of posts), but I did a search on the intervals for "how to initialize the mysql docker container". First I created a new directory to work, I called it mdir, and then created a file directory in which I wrote the epcis_schema.sql file, which creates a database and one table:
create database test; use test; CREATE TABLE testtab ( id INTEGER AUTO_INCREMENT, name TEXT, PRIMARY KEY (id) ) COMMENT='this is my test table';
Then I created a script called init_db in the file directory:
#!/bin/bash
(most of this script was taken from here: https://gist.github.com/pda/9697520 )
Here are the / run _db script files I created:
# start db set -e set -x
Finally, a Dockerfile to bind them:
FROM mysql MAINTAINER (me) <email> # Copy the database schema to the /data directory ADD files/run_db files/init_db files/epcis_schema.sql /tmp/ # init_db will create the default # database from epcis_schema.sql, then # stop mysqld, and finally copy the /var/lib/mysql directory # to default_mysql_db.tar.gz RUN /tmp/init_db # run_db starts mysqld, but first it checks # to see if the /var/lib/mysql directory is empty, if # it is it is seeded with default_mysql_db.tar.gz before # the mysql is fired up ENTRYPOINT "/tmp/run_db"
So, I connected to my mdir directory (which has a Dockerfile along with a file directory). Then I ran the command:
docker build --no-cache .
You should see the output as follows:
Sending build context to Docker daemon 7.168 kB Sending build context to Docker daemon Step 0 : FROM mysql ---> 461d07d927e6 Step 1 : MAINTAINER (me) <email> ---> Running in 963e8de55299 ---> 2fd67c825c34 Removing intermediate container 963e8de55299 Step 2 : ADD files/run_db files/init_db files/epcis_schema.sql /tmp/ ---> 81871189374b Removing intermediate container 3221afd8695a Step 3 : RUN /tmp/init_db ---> Running in 8dbdf74b2a79 + mysql_install_db 2015-03-19 16:40:39 12 [Note] InnoDB: Using atomics to ref count buffer pool pages ... /var/lib/mysql/ib_logfile0 ---> 885ec2f1a7d5 Removing intermediate container 8dbdf74b2a79 Step 4 : ENTRYPOINT "/tmp/run_db" ---> Running in 717ed52ba665 ---> 7f6d5215fe8d Removing intermediate container 717ed52ba665 Successfully built 7f6d5215fe8d
You now have an image of '7f6d5215fe8d'. I could run this image:
docker run -d 7f6d5215fe8d
and the image starts, I see the instance line:
4b377ac7397ff5880bc9218abe6d7eadd49505d50efb5063d6fab796ee157bd3
I could “stop” it and restart it.
docker stop 4b377 docker start 4b377
If you look at the logs, the first line will contain:
docker logs 4b377 Populate initial db var/lib/mysql/ ...
Then at the end of the logs:
Running with existing database in /var/lib/mysql
These are messages from the / tmp / run _db script, the first indicates that the database was unpacked from the saved (initial) version, the second indicates that the database already exists, so the existing copy was used.
Here is the ls -lR directory structure described above. Note that init_db and run_db are scripts with the execution bit set:
gregs-air:~ gfausak$ ls -Rl mdir total 8 -rw-r--r-- 1 gfausak wheel 534 Mar 19 11:13 Dockerfile drwxr-xr-x 5 gfausak staff 170 Mar 19 11:24 files mdir/files: total 24 -rw-r--r-- 1 gfausak staff 126 Mar 19 11:14 epcis_schema.sql -rwxr-xr-x 1 gfausak staff 1226 Mar 19 11:16 init_db -rwxr-xr-x 1 gfausak staff 284 Mar 19 11:23 run_db