Specific use of Docker anonymous mount and named mount

Specific use of Docker anonymous mount and named mount

Data volume

When talking about anonymous mount and named mount, we should first know what volumes are. Volumes refer to data volumes. We will use this volume for docker mount.

The purpose of a data volume is to create a special directory that can be used by one or more containers. It bypasses UFS, which is a union file system, and provides many functions:
(1) Data volumes can be shared or reused by multiple containers (2) Modifications to data volumes take effect immediately (3) Updates to data volumes do not affect images (4) Data volumes persist by default, even if the container is deleted (combining points 2 and 3, especially like nacos)

The command to view the data volume can be used:

docker volume --help

In fact, the command content is not much as follows:

insert image description here

In fact, you don't need to create a volume beforehand. You name it when you mount it. If it can't be found, a new data volume with a name instead of a hash code will be created based on the name you gave.

Anonymous and named mounts

With the previous knowledge about volumes, we can actually know the difference between anonymous mount and named mount. One is a mount without a volume name, and the other is a mount with a specified volume name.

For example, following the last mount, we specified the mount path. In fact, we can mount it more simply by not specifying the host path, and directly mount the docker container path with -v. Install nginx anonymously as follows.

# Anonymous mount -P uppercase P, map random port -v container path docker run -d -P --name nginx01 -v /etc/nginx nginx

In fact, a hash code will be returned, which is the name of the anonymously mounted data volume. You can also find the corresponding data volume based on this hash code. It is anonymous to you, but people will actually give it a name. We can use the volume ls command to view what data volumes are available.

docker volume ls

This named mount needs to specify the data volume, similar to the previous specified path mount, but this time we do not use a specific specified path but the name of the data volume.

# VOLUME NAME is currently displayed as an anonymous data volume. When -v is mounted, only the path in the container is written, not the path on the host. # Named mount # Pass -v volume name: path in the container docker run -d -P --name nginx02 -v juming-nginx:/etc/nginx nginx

Location of the data volume

Now that we have set up specific data volumes, mounted containers, and know the purpose of data volumes, where are the data volumes? After all, everything that is mounted is there, so just take a look at where it is to avoid accidentally deleting it.

In fact, the specific path under docker is:

/var/lib/docker/volumes/xxxx/_data

We can cd to this path to look at the data volume. For example, I cd to the second named data volume directory where nginx is mounted to look at the specific structure.

insert image description here

Let's summarize the ways we mount:

How to determine whether it is a named mount, an anonymous mount, or a specified path mount?
-v path in container# anonymous mount
-v data volume name:/path inside the container# Named mount
-v /host path:/container path# Mount the specified path

# Use -v to set the path in the container: ro rw to change the read and write permissions # ro readonly read only # rw readwrite read and write # If container permissions are set, the container will have limited permissions on the mounted data. 
docker run -d -P --name nginx04 -v juming-nginx:/etc/nginx:ro nginx
docker run -d -P --name nginx04 -v juming-nginx:/etc/nginx:rw nginx
# ro Whenever you see ro, it means that this path can only be operated through the host machine, and cannot be operated inside the container

This is the end of this article about the specific use of Docker anonymous mount and named mount. For more relevant Docker anonymous mount and named mount content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Docker container data volume named mount and anonymous mount issues
  • Implementation of named and anonymous mounts in docker

<<:  The difference between the four file extensions .html, .htm, .shtml and .shtm

>>:  Complete MySQL Learning Notes

Recommend

Explanation of the execution priority of mySQL keywords

As shown below: from table where condition group ...

MySQL configuration master-slave server (one master and multiple slaves)

Table of contents Ideas Host Configuration Modify...

Example code for hiding element scrollbars using CSS

How can I hide the scrollbars while still being a...

JS operation object array to achieve add, delete, modify and query example code

1. Introduction Recently, I helped a friend to ma...

About debugging CSS cross-browser style bugs

The first thing to do is to pick a good browser. ...

Deleting two images with the same id in docker

When I created a Docker container today, I accide...

MySQL database query performance optimization strategy

Optimize queries Use the Explain statement to ana...

Optimizing query speed of MySQL with tens of millions of data using indexes

1. The role of index Generally speaking, an index...

Detailed example of reading speed of js objects

1. Accessing literals and local variables is the ...

Detailed explanation of the transition attribute of simple CSS animation

1. Understanding of transition attributes 1. The ...

CentOS 6 Compile and install ZLMediaKit analysis

Install ZLMediaKit on centos6 The author of ZLMed...