Home >Database >Mysql Tutorial >How Do I Commit Data Changes to a MySQL Container Image?
How to Commit Data Changes to a MySQL Container Image
When using the official MySQL image to create a container, any data stored in the database will persist even after the container is stopped or deleted. This is because the data is stored in a persistent volume that is not part of the image itself.
However, in some cases, you may want to commit the database changes to the image so that the data is included in the new image. To do this, you need to create a custom MySQL image with no volumes.
Steps:
FROM mysql VOLUME ["/var/lib/mysql"]
<code class="sh">sudo docker build -t <image-name> .</code>
<code class="sh">sudo docker run --name mysql-psat1 -e MYSQL_ROOT_PASSWORD=secret -d <image-name> sudo docker exec -it mysql-psat1 bash > mysql -uroot -psecret -e 'create database liferay_psat1;' > mysql -uroot -psecret liferay_psat1 < /mnt/liferay_sql_dump.sql</code>
<code class="sh">sudo docker commit -m "Imported liferay sql dump" mysql-psat1 <image-name>:v1</code>
The new image will contain the newly created database and its data.
The above is the detailed content of How Do I Commit Data Changes to a MySQL Container Image?. For more information, please follow other related articles on the PHP Chinese website!