docker data volume container

docker data volume container

We have learned about docker's data volume before, and then we are learning about docker's data volume container, docker's data volume container
As the name suggests, it uses docker containers to store data.

First of all, docker's data volume container will reduce I / O performance, if possible, it is more convenient to use local data volume to store data.

First we generate and create a data volume container:

docker run -it -v /data --name data centos
It can be seen that the startup of the system is within seconds, and running the entire command will automatically enter the container,
At this point, a data directory will be generated in the root directory.
cd /
cd data
vim data.txt
And write the content data.
Then save and exit.
docker run -it --volumes-from data --name data1 centos
docker run -it --volumes-from data --name data2 centos

At this point, we will see that a data directory is automatically generated in both the data1 and data2 containers, and the content in this directory is the data container just generated
directory in .
#2. The impact of the state of the docker data volume container on the mount

What we tested just now is that the docker data volume container is running, but if the docker data volume container is closed, can it be mounted? We test
one time:
docker run -it --volumes-from data --name data6 centos

Frequent testing, we found that the docker data volume container can also be mounted in a closed state.
Let's create another file:
touch 1
It can be seen that not only can it be mounted, but the data volume container directory can also be changed, that is to say, even if the data volume container is stopped, the data volume
Containers can still be used.

#3. Cascading Mounting of Containers
At this time, because our data1 has been mounted on the data volume container data, we will start another container to see if we can change it to data1.
docker run -it --volumes-from data1 --name data3 centos
At this time, it is found that the data data volume is also mounted, which means that the docker data volume container can be mounted in cascade.

#4. Mount multiple data volume containers at the same time
We are creating a data volume container named data01, and the directory inside the data volume container is the / data01 directory:
docker run -it -v /data01 --name data01 centos

Then start another container data4 to remount both data volume containers:
docker run -it --volumes-from data --volumes-from data01 --name data4 centos

At this point, you can see that the two data volume containers with different names are all mounted.

#5. Overwrite problem when mounting data volume container with the same name
If we create another data volume container named data02, the directory inside the data volume container is also the / data directory:
docker run -it -v /data --name data02 centos
And create a data02.txt file in the directory:

At this point, start another container data5 and remount it:
docker run -it --volumes-from data --volumes-from data02 --name data5 centos

At this point, it can be seen that only one / data directory is generated and mounted, and this directory is mainly based on the data volume container mounted later.


#6. The impact of deleting the container on the data volume container

When our container is finished and stopped, in order to avoid the container still occupying certain system resources, it is often necessary to delete the entire container.
But we also want to keep the data that the original container was running on.
We can test this:
We create a 2 file in the data1 container, stop and delete the container data1.
At this time, 2 files can still be seen in the data volume container data, which means that the data volume container can persist data.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325252059&siteId=291194637