In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Before we begin
If you have some data that needs to be constantly updated and you want to persist the data, or if you need to share data between different containers, or if you need to share data between hosts and containers, you can use data volumes to meet these requirements.
Data volume definition
A data volume is a special directory that can be used by one or more containers. It bypasses UFS and provides many useful features:
Data volumes can be shared and reused between containers.
Changes to the data volume will take effect immediately.
The data volume defaults to always exist, even if the container is deleted.
Use data Volum
There are two ways to create a data volume: one is to create a data volume when you create a container, and the other is to create a data volume first, and mount the data volume when you create a container. Both methods are possible.
Create a data volume docker volume create demo-datademo-data create container use the-v (--volume) parameter to mount the data volume docker run-- name demo1-d\-v demo-data:/var/www/html nginx:alpinedocker run-- name demo2-d\-v demo-data:/var/www/html nginx:alpine list data volume docker volume lsDRIVER VOLUME NAMElocal demo-data View data volume details docker volume inspect demo-data [{"Driver": "local" "Labels": {}, "Mountpoint": "/ var/lib/docker/volumes/demo-data/_data", "Name": "demo-data", "Options": {}, "Scope": "local"}] Delete the data volume docker volume rm demo-dataError response from daemon: remove demo-data: volume is in use-[# omitted..]
Note: the data volume cannot be deleted because the data volume is being used by a container.
Test data volume host writes data hostname > / var/lib/docker/volumes/demo-data/_data/hosts.txt
Note: this directory corresponds to the demo-data data volume created.
Container write data docker exec-ti demo1 sh-c 'hostname > > / var/www/html/hosts.txt'docker exec-ti demo2 sh-c' hostname > > / var/www/html/hosts.txt' read data cat / var/lib/docker/volumes/demo-data/_data/hosts.txt node087c60cbe6147a6bc3c00c790 delete container data volume still retains docker stop demo1docker stop demo2 docker rm demo1docker rm demo2
The data volume still exists
Docker volume lsDRIVER VOLUME NAMElocal demo-data
Delete the data volume using the rm option if needed
Docker volume rm demo-data
The data volume no longer exists
Docker volume inspect demo-data [] Error: No such volume: demo-data Command help
Mount data volume parameters when creating a container
Docker run-- help | grep'\-v,-- volume list Bind mount a volume
Delete the data volume parameters when deleting the container (use with caution)
Docker rm-help | grep'\-v'-v,-- volumes Remove the volumes associated with the container
Data volume management command
Summary of docker volume-helpUsage: docker volume COMMANDManage volumesCommands: create Create a volume inspect Display detailed information on one or more volumes ls List volumes prune Remove all unused local volumes rm Remove one or more volumes
Finally, let's summarize the knowledge points in the article.
The data volume is designed to persist data, its life cycle is independent of the container, Docker will not be in the
The data volume is automatically deleted after the container is deleted. If you need to remove the data volume while deleting the container. You can delete the container
Use the docker rm-v command when using the.
Reference article
Doker&k8s Qun [703906133]
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.