In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "what are the main ways of Docker data management", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "what are the main ways of Docker data management?"
There are two main ways to manage data in an docker container:
Data volume (Volumes)
Mount host directory (Bind mounts)
Data volume
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 will always exist by default, even if the container is deleted
A data volume is a special directory that can be used by one or more containers. It bypasses UFS and provides many useful features:
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.
Docker provides two mount methods:-v and-mount. For new docker users, you should choose the-mount parameter. Experienced docker users are already familiar with-v or-- volume, but the-mount parameter is recommended.
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-volume
View information for the specified data volume
Docker volume 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 session-web and load a data volume into the container's / webapp directory
Docker run-- name session-web-d-p 8888 my-volume:/webapp 8080\ #-v my-volume:/webapp\-- mount source=my-volume,target=/webapp\ session-web:latest
Delete data Volum
Docker volume rm my-volume
Data volumes are designed to persist data, its declaration cycle is independent of the container, docker does not automatically delete data volumes after the container is deleted, and there is no mechanism such as garbage collection to handle data volumes that are not referenced by any containers. If you need to remove the data volume while deleting the container. You can use the docker rm-v command when deleting a container.
Unowned data volumes may take up a lot of space, to clean up, use the following command:
Docker volume prune
Mount the host directory
The path to the local directory and container directory must be absolute
Previously-if the local directory does not exist when using the-v parameter, docker will automatically create a folder for you
Now-- when using the-- mount parameter, docker will report an error if the local directory does not exist
The default permission for docker to mount the host directory is read and write, and users can specify it as read-only by adding readonly.
Use the-- mount flag to specify that the directory of a local host be mounted to the container
Docker run-- name session-web-d-p 8888 my-volume:/webapp 8080\ #-v my-volume:/webapp\-- mount type=bind,source=/src/webapp,target=/opt/webapp\ session-web:latest
The above command loads the host's / src/webapp directory into the container's / opt/webapp directory. 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.
Matters needing attention
The mount tag can also mount a single file from the host to the container
Docker run-- rm-it\ #-v $HOME/.bash_history:/root/.bash_history\-- mount type=bind,source=$HOME/.bash_history,target=/root/.bash_history\ ubuntu:17.10\ bash
This allows you to record the commands entered in the container.
At this point, I believe you have a deeper understanding of "what are the main ways of Docker data management". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.