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

Data Volume usage of docker Container

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

In general, people's understanding of the data volume of the docker container may stay at the conceptual level, but relatively little is known about the usage of the data volume of the docker container. Today I'm going to talk to you about how to use data volumes in docker containers.

1. Host directory mapping container directory

[root@docker03 / opt] # docker run-d-p 80:80-v / opt:/usr/share/nginx/html nginx:latest

11414881669cfd9f9c485668233a14fb6765835df1375f4808ced1c7391d76e3

two。 Write only the container directory and create new volumes (for container data persistence)

Question: the host directory and the container directory are synchronized in real time. For example, if the container directory file is deleted, the host will also be deleted. How to achieve persistence?

[root@docker03 / opt] # docker run-d-p 81:80-v / usr/share/nginx/html nginx:latest 8a5c405a8cffe8498e3bcc59fa99f7acd4d59ffa719507687806e1e3f764438f [root@docker03 / opt] # docker volume ls (View volumes) DRIVER VOLUME NAMElocal 3f8486a2c10268789478e87c0465f8f625a70e5526ebad829798fd438d2694f6

3. Specify the name of the volume

[root@docker03 / opt] # docker run-d-p 83:80-v ashuai:/usr/share/nginx/html nginx:latest 39ebc8852f8d71f071d348964b109e3dd4c2e78a7255cbd17aff670cdf3ea14d [root@docker03 / opt] # docker volume lsDRIVER VOLUME NAMElocal 3f8486a2c10268789478e87c0465f8f625a70e5526ebad829798fd438d2694f6local ashuai

4. View the properties of the corresponding volume

[root@docker03 / opt] # docker volume inspect ashuai [{"CreatedAt": "2019-12-12T17:18:18+08:00", # creation date "Driver": "local", "Labels": null, "Mountpoint": "/ var/lib/docker/volumes/ashuai/_data", # mount point corresponding to host "Name": "ashuai" # Volume name "Options": null, "Scope": "local"}]

5. Different containers mount the same host directory

[root@docker03] # docker run-d-p 84:80-- volumes-from 11414881669c nginx:latest

58cd0ba3902748af4546c1bfefacb3837e4764e763c6bc7562b9e6d6a6bd5fac

The above is the docker container data volume usage introduction, the content is more comprehensive, the editor believes that there may be some knowledge points that we may see or use in our daily work. I hope you can learn more from this article.

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