In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Data management
In the real environment, docker needs to persist data or share data among multiple containers, which involves data management operations of containers.
Data volumes: mapping data within containers to local host environment data volumes Container: maintaining data volumes using specific containers
The data volume (Data Volumes) is a special directory that can be used by the container, which is mapped directly into the container through the host operating system directory, similar to mount
Properties:
Can be shared between containers, reuse changes to the data in the volume will take effect immediately, whether in the operating system directory or in the container to update the data volume will not affect the container volume will always exist, knowing that there is no container to use, you can uninstall it
1. Create a data volume
Docker provides volume commands to manage data volumes, in addition to create (create), but also supports inspect (view details), ls (list existing data volumes), prune (clean up useless data volumes), rm (delete data volumes), etc.
[root@docker01] # docker volume create-d local testtest [root@docker01 ~] # ll / var/lib/docker/volumes/total 24drwxr-xr-x. 3 root root 19 Mar 9 23:21 1d300cc7b9123b4180bf8edb1f3ce130a8f317dba3332f21c55be23f27d0f30Mutual. 1 root root 32768 Mar 10 15:10 metadata.dbdrwxr-xr-x. 3 root root 19 Mar 10 15:10 test [root@docker01 ~] # docker volume lsDRIVER VOLUME NAMElocal 1d300cc7b91123b4180bf8edb1f3ce130a8f317dba3332f21c55be23f27d0f30local test
2. Bind data volumes
When creating a container, you can mount any path of the local host into the container as a data volume. The data volume created in this form becomes a bound data volume. Docker [container] run-- mount chooses to use the data volume.
-mount supports three types of data volumes:
Volume: normal data volume, mapped to host / var/lib/docker/volumes path
Bind: bind data volumes and map to the path specified by the host
Tmpfs: temporary data volume, which exists only in memory
Use the training/weapp image to create a web container and create a data volume to mount to the container's / opt/webapp directory.
[root@docker01 ~] # docker run-d-P-- name web-- mount type=bind,source=/webapp,destination=/opt/webapp:ro training/webapp python app.py# plus ro or rw indicates directory permission [root@docker01 ~] # docker run-d-P-- name web-- mount type=bind,source=/webapp,destination=/opt/webapp training/webapp python app.pyUnable to find image 'training/webapp:latest' locallylatest: Pulling from training/webappImage docker.io/training/webapp:latest uses outdated schema1 manifest format. Please upgrade to a schema2 image for better future compatibility. More information at https://docs.docker.com/registry/spec/deprecated-schema-v1/e190868d63f8: Pull complete 909cd34c6fd7: Pull complete 0b9bfabab7c1: Pull complete a3ed95caeb02: Pull complete 10bbbc0fc0ff: Pull complete fca59b508e9f: Pull complete e7ae2541b15b: Pull complete 9dd97ef58ce9: Pull complete a4c1b0cb7af7: Pull complete Digest: sha256:06e9c1983bd6d5db5fba376ccd63bfa529e8d02f23d5079b8f74a616308fb11dStatus: Downloaded newer image for training/webapp:latest89b39b0e540a3fc4730f5d72c2606dc162d4e6fa3f74eaf3c9b441d4e664576b data volume container
Users need to share some continuously updated data among multiple containers. You can use a data volume container, which is also a container, but it is designed to provide data volumes for other containers to mount.
Create a data container volume dbdata and mount a data volume to / dbdate in it
[root@docker01] # docker run-it-v / dbdate-- name dbdate ubuntu:18.04 root@f046a96ec64d:/# lsbin boot dbdate dev etc home lib lib64 media mnt opt proc root run
Other containers use-- volumes-from to mount data volumes in the dbdate container
[root@docker01 webapp] # docker run-it-volumes-from dbdate-name db1 ubunturoot@fafd91f30ad1:/# lsbin boot dbdate dev etc home lib lib64 media mnt opt proc root run
Test, you can see the created files for each other.
Root@f046a96ec64d:~# cd / dbdate/root@f046a96ec64d:/dbdate# touch aaroot@f046a96ec64d:/dbdate# lsaa root@fafd91f30ad1:/# cd dbdate/root@fafd91f30ad1:/dbdate# lsaa
If dbdata and db1 data volumes are deleted, they will not be deleted automatically. If you want to delete, use docker rm-v to delete them.
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.