In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
There are two main ways to persist data in a container:
Data volume (Data Volumes) data volume container (Data Volumes Dontainers)
Data volume
A data volume is a special directory that can be used by one or more containers and can bypass UFS (Unix File System).
Data volumes can be shared and reused between containers. Modifications to data volumes will take effect immediately and will not affect the default existence of mirrored data volumes, even if the container is deleted. Multiple data volumes can be mounted in one container.
Note: the use of data volumes is similar to mount directories or files under Linux.
Create a data volume
Example:
Docker run-- name nginx-data-v / mydir nginx
Execute the following command to view the details of the container construction:
Docker inspect Container ID
As can be seen from the test:
Docker automatically generates a directory as the mounted directory. Even if the container is deleted, the directory in the host will not be deleted.
Delete data Volum
Data volumes are designed to persist data, so deleting a container does not delete the data volume. If you want to delete the data volume while deleting the container, use the following command:
Docker rm-v container ID
This allows you to delete the volume as well as the container.
Mount the host directory as a data volume
Docker run-- name nginx-data2-v / host-dir:/container-dir nginx
This loads the / host-dir path of the host into the / container-dir of the container.
It is important to note that:
Host paths try to set absolute paths-what if you use relative paths?
The test gives the answer
If the host path does not exist, Docker will automatically create it.
TIPS
Dockerfile does not support this form for the time being.
Mount the host file as a data volume
Docker run-- name nginx-data3-v / file path: / container path nginx
Specify permissions
By default, mount permissions are read and write permissions. You can also use the: ro parameter to specify read-only permissions.
Example:
Docker run-- name nginx-data4-v / host-dir:/container-dir:ro nginx
In this way, only the files in / container-dir can be read in the container and cannot be modified.
Data volume container
If you have data that needs to be shared among multiple containers, consider using a data volume container at this time.
Create a data volume container:
Docker run-- name nginx-volume-v / data nginx
Use-volumes-from in other containers to mount the data volumes in the nginx-volume container.
Docker run-name v1-volumes-from nginx-volume nginxdocker run-name v2-volumes-from nginx-volume nginx
Like this:
V1 and v2 containers can share files in the nginx-volume container.
Even if nginx-volume stops, it won't make any difference.
The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.
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.