In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to manage Docker data storage Volumes". In daily operation, I believe many people have doubts about how to manage Docker data storage Volumes. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to manage Docker data storage Volumes". Next, please follow the editor to study!
The data of the default container is read and written to the storage layer of the container, and the data on the container will be lost when it is deleted. Therefore, we should try our best to ensure that write operations do not occur in the container storage layer. In order to achieve persistent storage of data, we need to choose a solution to save data. Currently, there are the following ways:
Volumes
Bind mounts
Tmpfs mounts
The following figure shows these three technologies:
Volumes
Volumes (data Volume) is a special directory located on the host machine that can be used by one or more containers and has the following features:
Data volumes can be shared and reused between containers
Writes to data volumes have no effect on mirroring
The data volume will always exist by default, even if the container is deleted
The purpose of using data volumes is to persist the data in the container to share between containers or to prevent data loss (data written to the container storage layer is lost).
The steps for using data volumes are generally divided into two steps:
Create a data volume
Use the-v or-- mount parameter to mount the volume to the specified directory of the container, so that all writes to that specified directory by the container are saved in the volume on the host.
Volume management
Create a volume:
$docker volume create my-vol
View volumes:
$docker volume lslocal my-vol$ docker volume inspect my-vol [{"driver": "local", "labels": {}, "mountpoint": "/ var/lib/docker/volumes/my-vol/_data", "name": "my-vol", "options": {}, "scope": "local"}]
We can see that the created volume my-vol is saved in the directory / var/lib/docker/volumes/, and all future write data for that volume will be saved in the directory / var/lib/docker/volumes/my-vol/_data.
Delete a volume:
$docker volume rm my-vol
Or delete all unused volumes:
Docker volume prune
Mount the data volume to the container directory
After creating a volume, we can use the volume by specifying the-v or-- mount parameter when running the container:
Use the-- mount parameter:
$docker run-d\-- name=nginxtest\-- mount source=nginx-vol,destination=/usr/share/nginx/html\ nginx:latest
Source specifies a file or folder within the container specified by the volume,destination.
Or use the-v parameter:
$docker run-d\-- name=nginxtest\-v nginx-vol:/usr/share/nginx/html\ nginx:latest
After a successful mount, the container reads or writes data from the / usr/share/nginx/html directory, actually reading or writing data from the nginx-vol data volume of the host. So volumes or bind mounts can also be seen as a way for containers and hosts to share files.
The-v parameter uses a colon to separate source and destination, with the first half of the colon being source and the second half being destination.
If you mount a data volume that does not already exist, docker will automatically create it. (therefore, the step of creating a data volume is not necessary)
If the directory to be mounted in the container is not an empty directory, the files in that directory will be copied to the data volume. (under bind mounts, the directory on the host always overrides the directory to be mounted in the container)
The-v parameter and the-- mount parameter generally have almost the same function, except that the data volume can only be mounted with the-- mount parameter when running a service.
Use read-only data volum
In some cases, we want a data volume to be read-only to a container, which can be achieved by adding the readonly option:
$docker run-d\-- name=nginxtest\-- mount source=nginx-vol,destination=/usr/share/nginx/html,readonly\ nginx:latest
Or use the-v parameter:
$docker run-d\-name=nginxtest\-v nginx-vol:/usr/share/nginx/html:ro\ nginx:latest at this point, the study on "how to manage Volumes for Docker data storage" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.