In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "what are the ways of mounting Docker data". In daily operation, I believe that many people have doubts about the way Docker data is mounted. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "what are the ways of mounting Docker data?" Next, please follow the editor to study!
1. Docker data management
There are two main ways to manage data in a container:
Data volume (Volumes)
Mount host directory (Bind mounts)
two。 Data volume
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.
Updates to data volumes do not affect mirroring.
The data volume defaults to always exist, even if the container is deleted.
Note: the use of data volumes is similar to mount directories or files under Linux. The files in the directory specified as the mount point in the image will be hidden to show that you are looking at the mounted data volume.
Two mounting methods are provided in Docker:-v and-- mount
New Docker users should choose the-mount parameter. Experienced Docker users are already familiar with-v or-- volume, but it is recommended to use the-mount parameter.
Create a data volume
Docker volume create my-volume
View all data volumes
Docker volume ls
View information for the specified data volume
Docker volume inspect my-volumedocker inspect my-volume
Start a container that mounts the data volume
When using the docker run command, use the-- mount flag to mount the data volume into the container.
Multiple volumes can be mounted in a single docker run.
Create a container named test-web and load a data volume into the container's / webapps directory
Docker run-- name test-web-p 8888my-volume:/webapps test-web:latest 8080-- mount source=my-volume,target=/webapps test-web:latestdocker run-- name test-web-p 8888purl 8080-v my-volume:/webapps test-web:latest
Delete data Volum
Docker volume rm my-volume
Data volumes are designed to persist data, its life cycle is independent of containers, Docker does not automatically delete data volumes after the container is deleted, and there is no mechanism such as garbage collection to deal with data volumes that are not referenced by any containers.
If you need to delete the container while removing the data volume, you can use the docker rm-v command when deleting the container.
Unowned data volumes may take up a lot of space, to clean up, use the following command:
Docker volume prune
3. Mount the host directory
Use the-- mount flag to specify that the directory of a local host be mounted to the container
Docekr run-- name test-web-d-p 8888 my-volume:/webapps test-web:latest 8080-- mount type=bind,source=/src/webapps,target=/opt/webapps test-web:latestdocekr run-- name test-web-d-p 8888 my-volume:/webapps test-web:latest
Previously-if the local directory does not exist when using the-v parameter, Docker will automatically create a file for you.
Now, if the local directory does not exist when using the-mount parameter, Docker will report an error.
The above command loads the host's / src/webapps directory into the / opt/webapps directory in the container. This feature is very convenient when testing, for example, users can place some programs in the local directory to see if the container is working properly.
The path to the local directory must be absolute.
The default permission for Docker to mount the host directory is read and write, and users can also specify read-only by adding readonly.
The mount tag can also mount a single file from the host to the container
Docker run-- rm-it-- mount type=bind,source=$HOME/.bash_history,target=/root/.bash_history ubuntu:17.10 bashdocker run-- rm-it-v $HOME/.bash_history:/root/.bash_history ubuntu:17.10 bash
This allows you to record the commands entered in the container.
At this point, the study of "what are the ways to mount Docker data" 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.