Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does docker manage container data

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the knowledge of "how docker manages container data". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Manage container data

You can manage data in a container in two ways: data volume (Data Volumns) and data volume container (Data Volumns containers).

Data volume (Data Volumns) concept:

Data volume exists in a special directory in one or more containers that bypasses the container's Union File System. Used to persist or share data. It is independent of the life cycle of the container. It has several characteristics:

The data volume is initialized after the container is created. If the underlying image has data at this mount point, it will copy the data to the data volume. (the directory hung on the host will not be copied)

Data volumes can be shared by multiple containers

The modification of the data volume is direct.

Changes to the data volume will not be included because you update the mirror.

Even if the container is deleted, the data volume continues to exist.

Add data volume [root@srv00 ~] # docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEhippo/nginx v1 2e1513eeaa0a 2 days ago 281.1 MBhippo/nginx v1.10 1e20546f8434 2 days ago 281.1 MB [root@srv00 ~] # docker run-it-v / etc/nginx Hippo/nginx:v1.10 [root@bab2e5725220 /] # ll / etc/nginx/total 32drwxr-xr-x 2 root root 25 May 20 07:40 conf.d...

You can see the contents of the original / etc/nginx directory in the data volume directory in the container.

You can modify a file configuration to see. And check the contents of the corresponding data volumes on the host.

[root@srv00 ~] # docker ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESbab2e5725220 hippo/nginx:v1.10 "/ bin/bash" About a minute ago Exited (0) 15 seconds ago hungry_ Jennings [root @ srv00 ~] # docker inspect bab2e5725220... "Mounts": [{"Name": "b6c506a65d5f495ca6ce06aeb30bb6472295d459bfbeb464e89681e17ffe3541", "Source": "/ var/lib/docker/volumes/b6c506a65d5f495ca6ce06aeb30bb6472295d459bfbeb464e89681e17ffe3541/_data", "Destination": "/ etc/nginx", "Driver": "local", "Mode": "," RW ": true "Propagation": ""}. [root@srv00 _ data] # docker rm bab2e5725220bab2e5725220 [root@srv00 ~] # cat / var/lib/docker/volumes/b6c506a65d5f495ca6ce06aeb30bb6472295d459bfbeb464e89681e17ffe3541/_data/nginx.conf.

The modification of the data volume is directly persisted in the corresponding place of the host.. Even if the container has been closed or deleted.

Mount the host directory [root@srv00 ~] # mkdir nginx [root@srv00 ~] # docker run-it-v / root/nginx:/etc/nginx hippo/nginx:v1.10 [root@c0750f9779b3 /] # ll / etc/nginx/ / opt/txt [root@cd8fa62d3b29 ~] # exitexit [root@srv00 ~] # docker exec-it db2 / bin/bash [root@72c21395c72b /] # cat / opt/txt db111111 [root@72c21395c72b /] # exitexit [root@srv00 ~] # docker inspect datastore [root @ srv00 ~] # docker inspect db1 [root@srv00 ~] # docker inspect db2... "Mounts": [{"Name": "6b650687d6d2a448006dcb2b966b5f69bb31d34cf3e93f5e3c3460b6fd6eea4a", "Source": "/ var/lib/docker/volumes/6b650687d6d2a448006dcb2b966b5f69bb31d34cf3e93f5e3c3460b6fd6eea4a/_data", "Destination": "/ opt", "Driver": "local", "Mode": "," RW ": true "Propagation": ". [root@srv00 ~] # docker volume inspect 6b650687d6d2a448006dcb2b966b5f69bb31d34cf3e93f5e3c3460b6fd6eea4a [{"Name": "6b650687d6d2a448006dcb2b966b5f69bb31d34cf3e93f5e3c3460b6fd6eea4a", "Driver": "local", "Mountpoint": "/ var/lib/docker/volumes/6b650687d6d2a448006dcb2b966b5f69bb31d34cf3e93f5e3c3460b6fd6eea4a/_data", "Labels": null}]

The data volumes hung by several containers are all the same. A data volume is actually created internally. Even if you delete all relevant running containers.. The data volume will not be deleted.

That's all for "how docker manages Container data". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report