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

What is Docker Volume?

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

Share

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

The main content of this article is to explain "what is Docker Volume". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what Docker Volume is.

One: brief introduction

Docker images are superimposed by multiple file systems (read-only layers). When we start a container, Docker loads the mirror layer and adds a read-write layer to it. If the running container modifies an existing file, the file will be copied from the read-only layer under the read-write layer to the read-write tier. The read-only version of the file still exists, but has been hidden by the copy of the file in the read-write layer. When you delete the Docker container and restart through the image, the previous changes will be lost. In Docker, the combination of read-only layer and read-write layer at the top is called Union FIle System (federated file system).

In order to preserve (persist) data and share data between containers, Docker put forward the concept of Volume. Simply put, Volume is a directory or file, which can bypass the default federated file system and exist on the host as a normal file or directory.

Two: data volume

1. Map the directory of the local server to the container's / data directory

Docker run-ti-- name myCentos-v / data centos:latest / bin/bash

Docker inspect myCentos

Check the results. The local server directory / var/lib/docker/volumes/f4e3133241c8ff27327bc7b9c43588202c22a1cde460ba52b762b75571fed257/_data is mapped to the container's / data directory.

Click (here) to collapse or open

"Mounts": [

{

"Name": "f4e3133241c8ff27327bc7b9c43588202c22a1cde460ba52b762b75571fed257"

"Source": "/ var/lib/docker/volumes/f4e3133241c8ff27327bc7b9c43588202c22a1cde460ba52b762b75571fed257/_data"

"Destination": "/ data"

"Driver": "local"

"Mode":

"RW": true

"Propagation":

}

]

two。 The changes under the container / data directory can be seen in the local service.

3. The-v command is equivalent to the VOLUME / data command in the Dockerfile file

4. Mount the specified directory of the local server to the container directory (this is not possible in Dockerfile files)

Docker run-ti-- name myCentos3-v / data/docker:/data/docker centos:latest / bin/bash

Third: data sharing & data volume container

Docker run-ti-name myCentos4-volumes-from myCentos3 centos:latest / bin/bash

Docker run-ti-- name myCentos5-- volumes-from myCentos3 centos:latest / bin/bash VOLUME / data

MyCentos4 and myCentos5 share the data volumes of the container myCentos3, and myCentos3 is a special data volume container.

A common usage scenario is to use pure data containers to persist databases, configuration files, data files, and so on. The data volume container can be used without startup.

Fourth, use the data volume container to back up and restore the data volumes in order to realize the data migration.

Backup:

Docker run-name myCentos5-volumes-from myCentos3-v / backup:/backup centos:latest tar czvf / backup/backup.tar / data/docker

Restore:

Docker run-- name myCentos6-v / data/docker centos:latest / bin/bash (create a container with data volumes)

Docker run-- name myCentos7-- volumes-from myCentos6-v / backup:/backup centos:latest tar xzvf / backup/backup.tar

Mv. / data/docker

Five: delete the data volume container

Docker rm-v

At this point, I believe you have a deeper understanding of "what Docker Volume is", might as well come to the actual operation of it! 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.

Share To

Servers

Wechat

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

12
Report