What is Let’s first look at the concept of Docker: Package the application and the running environment into a container. The running can be accompanied by the container, but we hope that the data is persistent and that it is possible to share data between containers. If the data generated by the Docker container is not saved as part of the image by generating a new image through docker commit, then when the container is deleted, the data will naturally disappear. In order to save data in docker we use volumes. In a word: It is somewhat similar to RDB and AOF in our Redis What can I do? A volume is a directory or file that exists in one or more containers and is mounted to the container by Docker, but does not belong to the Union File System, so it can bypass the Union FileSystem to provide some features for persistent storage or shared data: The design purpose of the volume is data persistence, which is completely independent of the life cycle of the container. Therefore, Docker will not delete the mounted data volume when the container is deleted. Features:
Summarize:
Data Volume Direct command addition docker run -it -v /host absolute path directory:/container directory image namedocker run -it -v /host absolute path directory:/container directory:ro image name//with command, specify access rights, ro: read only Check whether the data volume is mounted successfully: docker inspect container id Add using DockerFile Create a new mydocker folder in the root directory and enter You can use the VOLUME instruction in a Dockerfile to add one or more data volumes to the image. DockerFile Build For writing DockerFile, you can refer to the DockerFile files of each image in DockerHub, such as tomcat: https://github.com/docker-library/tomcat/blob/300ac03f4696c761a81fa10afbb893f3368061de/8.5/jdk8/openjdk-buster/Dockerfile #volume test FROM centos VOLUME ["/dataVolumeContainer1","/dataVolumeContainer2"] CMD echo "finished,-------success1" CMD /bin/bash Generate an image after build Get a new image zzyy/centos Run container Through the above steps, the volume directory address in the container is already known, where is the corresponding host directory Remark: Docker mounts the host directory. Docker access appears cannot open directory, Permission denied Solution: Add a --privileged=true parameter after mounting the directory Data volume container What is The named container mounts the data volume, and other containers share data by mounting this (parent container). The container that mounts the data volume is called a data volume container. Transitive sharing between containers (--volumes-from) docker run -it --name dco2 --volumes-from dc01 zzyy/cenos // dc01 is the first created container, dco2 inherits dc01 to achieve data sharing The data volume is mounted by the parent container (dc01). If dc01 is mounted on dc02 and dc03 and then deleted, the data volume will still be valid. The configuration information is transferred between containers, and the life cycle of the data volume continues until no container uses it. Summarize This is the end of this article about Docker container data volumes. For more information about Docker container data volumes, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
>>: JavaScript to implement input box content prompt and hidden function
As the domestic network environment continues to ...
MySQL version 5.0 began to support stored procedu...
Table of contents 1. Introduction 2. Use 1. Diffe...
The tee command is mainly used to output to stand...
This article uses an example to illustrate the me...
1. Top-level usage 1. Install cnpm npm i -g cnpm ...
JavaScript - Principles Series In daily developme...
Preface The default database file of the MySQL da...
Table of contents 1. Knowledge description of the...
When the token expires, refresh the page. If the ...
1.What is margin? Margin is used to control the sp...
Table of contents Written in front 1. Ngixn image...
background Basic Concepts CSS filter property app...
<div id="root"> <h2>Keep go...
For Linux system administrators, it is crucial to...