问题
I pulled a MySQL docker(latest) & after running it I am trying to commit my container after adding some Data & New Schema's & tables in this mysql docker instance.
For Reference i am following this link -> http://www.servermom.org/pull-docker-images-run-docker-containers/3225/
But even after trying with multiple variations i am not achieving what i intend to. So what i am doing is after adding new tables and schema to my container i am committing & pushing to Docker hub as mentioned in the link.
After that i am deleting deleting the 1st pulled image as i have added new data to a container and committed as a new image with a different Tag .. i am deleting the 1st pulled image. (The reason i am doing this is because lets say if i am changing my machine i can get my data intact when i do a docker pull of my committed image)
Just like git if i commit & push and lets say my machine broke down so in the new machine i just have to do a git pull and i will get everything without any loss. So i am not able to understand how any why docker is not saving changes
回答1:
Data for mysql image is stored in a volume. That means that the files inside that volume are not part of the image, but stored on the host and assigned to one or more running containers.
To achieve what you want I see 2 options:
1) build a custom mysql image, where you change the storage path of mysql outside of a volume (or simply create a new mysql image without volumes).
2) you can extend the image and include the schema modification commands at container startup with a custom run script/entrypoint
Here is the documentation page about volumes: https://docs.docker.com/engine/admin/volumes/volumes/
来源:https://stackoverflow.com/questions/45808227/docker-container-image-not-saving-changes