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
Now most projects have begun to be deployed on Do...
Table of contents 1. Insert statement 1.1 Insert ...
You can save this logo locally as a .rar file and...
1. Link's to attribute (1) Place the routing ...
The difference between := and = = Only when setti...
Copy code The code is as follows: <select> ...
A common suggestion is to create indexes for WHER...
This article mainly introduces the implementation...
In this post, we’ll use the :placeholder-shown ps...
Table of contents Preface Introduction JavaScript...
10.4.1 The difference between Frameset and Frame ...
MySQL is an open source, small relational databas...
Table of contents 1. Extracting functions 2. Merg...
This seems to be no longer possible with the new ...
Table of contents React upload file display progr...