<> one , What is a container data volume ?

Why? Docker Container data volume required ? Because when we package the application and running environment to form a container to run , Operation can accompany the container , But our requirements for data , I hope it can last ! It's like , You install one MySQL, As a result, the container was accidentally deleted , Isn't that equivalent to deleting the database and running away , This is obviously not allowed to happen !

In order to save data in Docker We can use volumes in ! Let data mount To our local ! In this way, data will not be lost due to container deletion !

Function of container roll :
A volume is a directory or file , Exists in one or more containers , from docker Mount to container , But not a federated file system , So it can bypass Union File System ,
Provides features for continuous storage or sharing of data : Volume is designed for data persistence , Completely container independent lifecycle , therefore Docker The attached data volumes of the container will not be deleted when it is deleted .

Characteristics of container roll :

* Data volumes can share or reuse data between containers
* Changes in the volume can take effect directly
* Changes in the data volume are not included in the update of the mirror
* The life cycle of a data volume lasts until no container uses it
therefore : Sum up one sentence : Is container persistence , And inheritance and data sharing between containers !

<> two , Using data volumes

<>1, mount
# command docker run -it -v Host absolute path directory : Contents in container Image name # test [root@TR ~]# ll total 1052
drwxr-xr-x 9 1001 1001 4096 Nov 29 20:54 nginx-1.21.4 -rw-r--r-- 1 root root
1070260 Nov 29 20:42 nginx-1.21.4.tar.gz # 1, Create a test folder “pangtaiyi” [root@TR ~]#
mkdir pangtaiyi [root@TR ~]# ll total 1056 drwxr-xr-x 9 1001 1001 4096 Nov 29
20:54 nginx-1.21.4 -rw-r--r-- 1 root root 1070260 Nov 29 20:42 nginx-1.21.4.tar.
gz drwxr-xr-x 2 root root 4096 Dec 1 21:40 pangtaiyi # 2, function Centos image , And put the
“/root/pangtaiyi” Directory and local “/root/pangtaiyi” Directory Association [root@TR ~]# docker run -it -v
/root/pangtaiyi:/root/pangtaiyi centos /bin/bash [root@2cb343981d5b /]# ls bin
dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp
usrvar [root@2cb343981d5b /]# cd root [root@2cb343981d5b ~]# ls anaconda-ks.cfg
anaconda-post.log original-ks.cfg pangtaiyi [root@2cb343981d5b ~]# cd pangtaiyi
# 3, stay “pangtaiyi” Create a folder “pangtaiyi.txt” file [root@2cb343981d5b pangtaiyi]#
touch pangtaiyi.txt [root@2cb343981d5b pangtaiyi]# ls pangtaiyi.txt # 4, Exit container ,
Check whether there is file generation under the local associated directory [root@2cb343981d5b pangtaiyi]# [root@TR ~]# [root@TR ~]# cd
pangtaiyi [root@TR pangtaiyi]# ll total 0 -rw-r--r-- 1 root root 0 Dec 1 21:42
pangtaiyi.txt
<>2, Query the mounting status
# grammar “docker inspect container ID” [root@TR ~]# docker inspect 2cb343981d5b [ { "Id":
"2cb343981d5b4181869b807b51c08af487534333073013186ee4ed540f23b3d5", "Created":
"2021-12-01T13:41:54.89582656Z", "Path": "/bin/bash", "Args": [], "State": {
"Status": "running", "Running": true, "Paused": false, "Restarting": false,
"OOMKilled": false, "Dead": false, "Pid": 1850114, "ExitCode": 0, "Error": "",
"StartedAt": "2021-12-01T13:41:55.330564955Z", "FinishedAt":
"0001-01-01T00:00:00Z" }, .................. "Mounts": [ { "Type": "bind",
"Source": "/root/pangtaiyi", "Destination": "/root/pangtaiyi", "Mode": "", "RW"
: true, "Propagation": "rprivate" } ], ........ } ]
You can see in Mounts in , There are two paths we mounted before .

Technology
©2019-2020 Toolsou All rights reserved,
Solve in servlet The Chinese output in is a question mark C String function and character function in language MySQL management 35 A small coup optimization Java performance —— Concise article Seven sorting algorithms (java code ) use Ansible Batch deployment SSH Password free login to remote host according to excel generate create Build table SQL sentence Spring Source code series ( sixteen )Spring merge BeanDefinition Principle of Virtual machine installation Linux course What are the common exception classes ?