Docker Data generated by the container , If you do not back up , After the container instance is deleted , Naturally, there is no data in the container . In order to save data in docker We use volumes in .

characteristic :

1: Data volumes can share or reuse data between containers

2: Changes in the volume can take effect directly in real time

3: Changes in the data volume are not included in the update of the mirror

4: The life cycle of a data volume lasts until no container uses it

Mount command :
# docker run -it --privileged=true -v / Host absolute directory :/ Absolute directory in container Container name docker run -it
--privileged=true -v /tmp/my_dir:/tmp/docker_dir ubuntu /bin/bash
After mounting , have access to
docker inspect container ID
View the information in the container , find "Mount" node
{ ... "Mounts": [{ { "Type": "bind", // Absolute directory of the host "Source": "/tmp/my_dir", //
Absolute directory in container "Destination": "/tmp/docker_dir", "Mode": "", "RW": true,
"Propagation": "rprivate" } ] ... }
When container stop after , Continue to update files under the directory in the host machine , When the container again start Then you can see the updated file .

be careful : When multiple containers mount the directory of the same host , Then these containers can read and write files under the directory of the host .

Read write rules :ro and rw

The mounted directory is for the container directory , Default is RW( Read only write only ) Permissions for , The following commands are used to control the read and write rules :
# Set the read-only write permission of the container directory docker run -it -privileged=true -v
/tmp/my_dir:/tmp/docker_dir:rw ubuntu /bin/bash # Set container directory read-only permission docker run -it
-privileged=true -v /tmp/my_dir:/tmp/docker_dir:ro ubuntu /bin/bash #
If set ro jurisdiction , When updating files in the container directory , Will prompt :touch: cannot touch 'd.txt': Read-only file system
Volume inheritance and sharing :--volumes-from
# Create the first container docker run -it --privileged=true --name do1 -v
/tmp/my_dir:/tmp/docker_dir ubuntu /bin/bash # When creating the second container , Inherit the volume rule of the first container , format : #
docker run -it --volumes-from Parent class container name ubuntu /bin/bash docker run -it
--privileged=true --name do2 --volumes-from do1 ubuntu /bin/bash
  In this way, the second container also has the same host directory mount point as the first container .

©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 ?