Docker: Committing Data in a MySQL Container
When trying to commit data to a MySQL container image, it's important to understand the impact of data volumes.
The official MySQL Docker image uses data volumes to store its data. While this allows for data persistence beyond the lifespan of a container, it also means that data is not included in the committed image.
To commit data to an image along with MySQL, create a custom base image without volumes. For example, create a new image based on the MySQL image with the following Dockerfile:
FROM mysql:latest RUN rm -rf /var/lib/mysql/ CMD ["mysqld"]
Then, build the custom image:
docker build -t my-custom-mysql-image .
With this custom base image, you can create containers and import data as you did before:
docker run --name my-mysql-container -e MYSQL_ROOT_PASSWORD=secret -d my-custom-mysql-image docker exec -it my-mysql-container bash mysql -uroot -psecret -e 'create database liferay_psat1;' mysql -uroot -psecret liferay_psat1Now, when you commit the container as a new image:
docker commit -m "Imported liferay sql dump" my-mysql-container my-custom-mysql-image:v1The imported data will be included in the committed image and available when starting new containers with that image.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3