In the previous article, I introduced the basic knowledge of Docker: how to mount a local directory. Today, I will introduce two ways to manage data volumes in Docker. The specific contents are as follows: What is a data volumeData volume: A volume is a specific file or folder that exists in one or more containers. This directory exists in the host machine in a form independent of the union file system and facilitates data sharing and persistence. Why use data volumes? Problems with Docker layered file system: Two ways to manage data volumes
1. Bind mount Bind mount is to mount the directory or file on the host into the container. Intuitive and efficient to use, easy to understand. Run a container using the nginx image in the background and mount the host's /data directory to the container's directory /usr/share/nginx/html [root@server1 ~]# docker run -d --name demo -v /data:/usr/share/nginx/html nginx Switch to the foreground to run, and check the contents of the specified directories of the host and container respectively. They are the same. This is because this method of mounting is the same as the mount method we usually use. The original data is hidden and replaced with the data of the host machine. [root@server1 ~]# docker exec -it demo bash The default permissions for bind mount are read-write (rw), and you can specify read-only (ro) when mounting. The path specified by the -v option will be automatically created when mounting if it does not exist. docker run -it --name vm1 \ /etc/yum.repos.d/dvd.repo:/etc/yum.repos.d/dvd.repo:ro rhel7 bash 2. Docker managed volume Bind mount must specify the host file system path, which limits portability. [root@server1 ~]# docker volume create webdata #Create a volume named webdata[root@server1 ~]# docker rm -f demo #Delete the volume created above[root@server1 ~]# docker run -d --name demo -v webdata:/usr/share/nginx/html nginx #Mount the webdata volume to the /usr/share/nginx/html directory in the container and run a container Mount the created webdata volume to the /usr... directory of the container [root@server1 ~]# docker rm -f demo [root@server1 ~]# docker run -d --name demo -v /usr/share/nginx/html nginx 67ab13a7b24c19c53f4ce117136b9d0e4dec93c615a0192ead919d10e6c2acae
ls /var/lib/docker/volumes/2ca22fd769e4b7b6f5a02dd96fe8d47a6df5578074c0d340ced3ab33b25456ca/_data Comparison between bind mount and Docker managed volumes Similarities: Both are paths in the host file system. This concludes this article on two ways to manage volumes in Docker. For more information about Docker volumes, please search for previous articles on 123WORDPRESS.COM or continue browsing the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed explanation of the use of IF(), IFNULL(), NULLIF(), and ISNULL() functions in MySQL
>>: Several ways to remove the dotted box that appears when clicking a link
1. Parent components can pass data to child compo...
login.html part: <!DOCTYPE html> <html l...
<p><b>This is bold font</b></...
Preface What is state We all say that React is a ...
This article example shares the specific code of ...
MySql uses joined table queries, which may be dif...
How to use if in Linux to determine whether a dir...
Achieve results Implementation Code <h1>123...
MySQL master-slave configuration and principle, f...
How do I download MySQL from the official website...
Hello everyone, today I want to share with you ho...
sshd SSH is the abbreviation of Secure Shell, whi...
Write at the beginning This article only covers E...
This article shares with you the graphic tutorial...
In the case of concurrent access, non-repeatable ...