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

K3s Getting Started Guide - Detailed Tutorial on Running K3s in Docker

What is k3d? k3d is a small program for running a...

How to create a responsive column chart using CSS Grid layout

I have been playing around with charts for a whil...

The latest virtual machine VMware 14 installation tutorial

First, I will give you the VMware 14 activation c...

Sample code for implementing menu permission control in Vue

When people are working on a backend management s...

CentOS uses local yum source to build LAMP environment graphic tutorial

This article describes how to use the local yum s...

Automatic backup of MySQL database using shell script

Automatic backup of MySQL database using shell sc...

How complicated is the priority of CSS styles?

Last night, I was looking at an interview question...

How to use nginx to simulate blue-green deployment

This article introduces blue-green deployment and...

How to add docker port and get dockerfile

Get the Dockerfile from the Docker image docker h...

Analysis of MySQL latency issues and data flushing strategy process

Table of contents 1. MySQL replication process 2....

Detailed explanation of Docker compose orchestration tool

Docker Compose Docker Compose is a tool for defin...

Learn MySQL index pushdown in five minutes

Table of contents Preface What is index pushdown?...

MySQL installation tutorial under Windows with pictures and text

MySQL installation instructions MySQL is a relati...

How to create your own Docker image and upload it to Dockerhub

1. First register your own dockerhub account, reg...