In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
To understand Docker Volume, we first need to understand how the Docker file system works. Docker images are superimposed by read-only layers of multiple file systems. When a container is started with the command docker run, Docker loads the read-only mirror layer and adds a read-write layer at the top of the mirror stack. If the running container modifies an existing file, the file will be copied from the read-only layer below the read-write layer to the read-write layer, but the read-only version of the file still exists, but it has been hidden by a copy of the file in the read-write layer.
When the Docker container is deleted and restarted through the image, previous changes in the read-write layer will be lost. In Docker, the combination of the read-only layer and the read-write layer at the top is called Union File System (federated file system), or UnionFS, which uses an important resource management technology called write-time replication. Copy-on-write (copy-on-write), also known as implicit sharing, is a resource management technology that replicates modifiable resources efficiently. For a duplicate resource, if you do not modify it, you do not need to create a new resource immediately, the resource can be shared. A new resource is created only when changes occur. This greatly reduces the consumption of unmodified resource replication. In fact, the concept of COW is no stranger to programmers, and it is widely used in various fields, such as the copy action of Internal table in ABAP, the copy implementation of Java string, and so on. Docker creates containers based on UnionFS.
Let's look at a practical example.
Use the command line docker run-- help to view the help documentation for this command. The function of-h is to specify the hostname of the container.
Create a new container using the command line:
Docker run-it-- name jerry-container-test-h CONTAINER-v / data busybox / bin/sh
The name is jerry-container-test and a volume / data is created with-v
Once created, execute cd / data in the container to enter this directory, which is still empty at this time.
Docker ps to view container status:
Now I want to know which internal directory is used on the host to implement this volume.
Use the command docker inspect jerry-container-test to view the keyword "volumes":
Get the directory where the container / data is implemented on the host:
/ var/lib/docker/volumes/96aa969033ee7e6d7ff607a0a47de5a5866613a422518ed3f86fee6240bae8cc/_data
Now I use the touch command on the host to create a file directly in this directory:
Sudo touch / var/lib/docker/volumes/96aa969033ee7e6d7ff607a0a47de5a5866613a422518ed3f86fee6240bae8cc/_data/test.s
Now switch to the container and use ls to see the files created in internal folder directly on the host using the touch command.
For more original Jerry articles, please follow the official account "Wang Zixi":
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.