Detailed explanation of Bind mounts for Docker data storage

Detailed explanation of Bind mounts for Docker data storage

Before reading this article, I hope you have a preliminary understanding of Volumes. For details, please refer to this article:

Docker Data Storage Volumes Detailed Explanation

By default, the reading and writing of container data occurs at the container's storage layer. When the container is deleted, the data on it will be lost. Therefore, we should try to ensure that no write operations occur in the container storage layer. In order to achieve persistent storage of data, we need to choose a solution to save data. Currently, there are several ways:

  • Volumes
  • Bind mounts
  • tmpfs mounts

The following diagram illustrates these three techniques:

Bind mounts

The Bind mounts mode is very similar to Volumes. The difference is that the Bind mounts mode mounts any file or folder on the host to the container, while Volumes essentially mounts an area managed by the Docker service (the default is a folder under /var/lib/docker/volumes) to the container.

The use of bind mounts is similar to that of volumes, and the host files are mounted in the container through -v or --mount parameter. Here is an example:

When using the --mount parameter, you need to specify type=bind :

$ docker run -d \
 --name=nginxtest \
 --mount type=bind,source=/usr/local/web,destination=/usr/share/nginx/html \
 nginx:latest

The above example mounts the /usr/local/web folder on the host to the /usr/share/nginx/html folder in the container.

Or use the -v parameter:

$ docker run -d \
 --name=nginxtest \
 -v /usr/local/web:/usr/share/nginx/html \
 nginx:latest

After the mount is successful, the container reads or writes data from the /usr/share/nginx/html directory, which actually reads or writes data from the /usr/local/web directory of the host. Therefore, Volumes or Bind mounts can also be seen as a way for containers and hosts to share files.

If you use Bind mounts to mount a host directory to a non-empty directory in a container, the files in the non-empty directory in the container will be hidden, and the files that the container can access when accessing this directory are all from the host directory. This is also the biggest behavioral difference between Bind mounts mode and Volumes mode.

Bind mounts usage scenarios

Please refer to this article: Docker Data Storage Summary

References

https://docs.docker.com/storage/bind-mounts/

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links

You may also be interested in:
  • How to modify the storage location of Docker default images and containers
  • Detailed explanation of Docker's persistent storage and data sharing
  • Docker Data Storage Volumes Detailed Explanation
  • Docker storage driver introduction
  • Summary of Docker Data Storage
  • Docker data storage tmpfs mounts detailed explanation
  • Solution to the problem of insufficient storage resource pool of Docker server

<<:  Detailed explanation of JDBC database link and related method encapsulation

>>:  JavaScript to implement login slider verification

Recommend

Linux centOS installation JDK and Tomcat tutorial

First download JDK. Here we use jdk-8u181-linux-x...

Handwritten Vue2.0 data hijacking example

Table of contents 1: Build webpack 2. Data hijack...

Import CSS files using judgment conditions

Solution 1: Use conditional import in HTML docume...

Detailed steps for completely uninstalling MySQL 5.7

This article mainly summarizes various problems o...

Detailed explanation of Vue's ref attribute

Summarize This article ends here. I hope it can b...

Nginx merges request connections and speeds up website access examples

Preface As one of the best web servers in the wor...

Commonplace talk about MySQL event scheduler (must read)

Overview MySQL also has its own event scheduler, ...

A brief discussion on the mysql execution process and sequence

Table of contents 1:mysql execution process 1.1: ...

Difference between HTML ReadOnly and Enabled

The TextBox with the ReadOnly attribute will be di...

Historical Linux image processing and repair solutions

The ECS cloud server created by the historical Li...

Full steps to create a password generator using Node.js

Table of contents 1. Preparation 2. Writing comma...

Install Apache2.4+PHP7.0+MySQL5.7.16 on macOS Sierra

Although Mac systems come with PHP and Apache, so...