Today continue to look at the Docker related things.
Before, to understand the data volume and volume container is because when you first understand the Docker mode of work encountered two questions: about Docker data persistence, and Docker how to share data. By understanding data volumes and data volume containers, It is now possible to know Docker how to share data and persist data as a whole. In the process of continuous learning, to understand that Docker create a container by mirroring, in fact, the mirror adds a layer of read and write layer, our changes to the Docker data are in this read-write layer occurs.
So the question is, if I'm going to create a Web or database container, install the software in it, such as Tomcat or MySQL. How do I save these changes so that I can use them later when I create a container?
The previous data volume and data volume container have saved our changes to the file. Now this is actually a need to persist the created container and make it a mirror image. We used to create containers using the Docker command, and many of the newly created containers have some installed software, This is what you use. This is also very simple to achieve, Docker to us a command-commit. The above requirements can be achieved by this command.
First, create a container,
sudo docker run-i-T--name Mungo Docker/whalesay/bin/bash
Here I will create a test.txt file in the/use/local directory.
Here is the protagonist, using the commit command to submit the container. Before submitting, you can look at the current mirror image of the computer.
sudo docker images
sudo docker commit Mungo Mungo:v2
sudo docker images
By contrast, you can see that there is more than one repository for Mungo,tag v2 in the mirror of this machine. Use this image below to create a container to see if the Test.txt files created in the previous/use/local directory are still there.
sudo docker run-i-t--name mungo_v2 MUNGO:V2
Notice here that when I create a container using a mirror named Mungo, I add a v2, which is to create a mirror-specified tag, the default tag is latest can not be specified, if not to pass : to specify.
As you can see here, the file you created before is still there. Viewing the container through the PS command also reveals that I use a different mirror to create the container, but the contents of the container are the same.
As you can see from the above operation, the commit command can submit existing containers and modifications as a new mirror, which also saves the read-write layer content. However, since the previous modifications were made each time the container was created with a new mirror, the commit command could implement the save read-write layer data. But it is not suitable for data persistence.