Reputation: 637
If I create a database in a mysql container and commit it as a new image. The new image does not persit the database. Here is the scenario
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql
docker exec -it some-mysql bash
root@e756b3aa719b:/# mysql -uroot -pmy-secret-pw
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> create database michael;
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| michael |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
mysql> exit
Bye
root@e756b3aa719b:/# exit
exit
Then I commit this container as an image
docker commit 486932c6d7e7 bdd/myproj:1.0
If I create a container from this image the database is not here
docker run --name newbdd -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mybdd/myproj:1.0
docker exec -it newbdd bash
root@004f86506ebf:/# mysql -uroot -pmy-secret-pw
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)
What's really weird is that the mysql client kept the history of the command "create database michael" but the server does not keep the database michael.
I don't understand why.
Upvotes: 1
Views: 439
Reputation: 13085
Working as intended. Data inside a container is not typically a best practice. The mysql base image specifies the data directory as a volume which does not persist.
Upvotes: 3