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:
The following diagram illustrates these three techniques: Volumes Volumes are special directories on the host that can be used by one or more containers. They have the following characteristics:
The steps to use data volumes are generally divided into two steps:
Volume Management Create a Volume: $ docker volume create my-vol View Volumes: $ docker volume ls local my-vol $ docker volume inspect my-vol [ { "Driver": "local", "Labels": {}, "Mountpoint": "/var/lib/docker/volumes/my-vol/_data", "Name": "my-vol", "Options": {}, "Scope": "local" } ] We can see that the created Volume my-vol is saved in the directory To delete a volume: $ docker volume rm my-vol Or delete all unused volumes: docker volume prune Mount the data volume to the container directory After creating a Volume, we can use it by specifying the -v or --mount parameter when running the container: Use the $ docker run -d \ --name=nginxtest \ --mount source=nginx-vol,destination=/usr/share/nginx/html \ nginx:latest
Or use the -v parameter: $ docker run -d \ --name=nginxtest \ -v nginx-vol:/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 nginx-vol data volume of the host machine. Therefore, Volumes or Bind mounts can also be seen as a way for containers and hosts to share files.
Using read-only data volumes In some cases, we want a data volume to be read-only for a container, which can be achieved by adding the readonly option: $ docker run -d \ --name=nginxtest \ --mount source=nginx-vol,destination=/usr/share/nginx/html,readonly \ nginx:latest Or use the -v parameter: $ docker run -d \ --name=nginxtest \ -v nginx-vol:/usr/share/nginx/html:ro \ nginx:latest Volumes usage scenarios Please refer to this article: Docker Data Storage Summary References
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:
|
<<: Detailed explanation of two ways to dynamically change CSS styles in react
>>: Detailed explanation of JDBC database link and related method encapsulation
An interesting discovery: There is a table with a...
1. What is HTML HTML (HyperText Markup Language):...
Preface Mobile devices have higher requirements f...
If you use docker for large-scale development but...
I encountered a very unusual parameter garbled pro...
BEM is a component-based approach to web developm...
>>>>>Ubuntu installation and confi...
The <input> tag The <input> tag is us...
This article is welcome to be shared and aggregat...
Table of contents 1. Download MySQL 1.1 Download ...
Table of contents Requirements: Implementation st...
Keywords General The title cannot contain words l...
The reason for writing this article is that I wan...
1. Pull the image docker pull registry.cn-hangzho...
1. Search for redis image docker search redis 2. ...