Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Docker data store Bind mounts

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article focuses on "how to use Docker data storage Bind mounts", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use Docker data storage Bind mounts.

The data of the default container is read and written to the storage layer of the container, and the data on the container will be lost when it is deleted. Therefore, we should try our best to ensure that write operations do not 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 the following ways:

Volumes

Bind mounts

Tmpfs mounts

The following figure shows these three technologies:

Bind mounts

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

Bind mounts is similar to volumes in that the host file is mounted to the container through the-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, actually reading or writing data from the host's / usr/local/web directory. So 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 the host directory to a non-empty directory in the container, the files in the non-empty directory in the container will be hidden, and the files that the container can access to this directory come from the host directory. This is also the biggest difference in behavior between bind mounts mode and volumes mode.

At this point, I believe you have a deeper understanding of "how to use Docker data storage Bind mounts". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report