# Docker 数据卷（volume）

资料

[Docker容器学习梳理 - Volume数据卷使用](https://www.cnblogs.com/kevingrace/p/6238195.html)

[Docker容器的数据卷（data volume），数据卷容器，数据卷的备份和还原。](https://www.cnblogs.com/yaowen/p/8431710.html)

volume是存在于一个或多个容器中的特定文件或文件夹，这个目录以独立于联合文件系统的形式在宿主机中存在，并为数据库共享与持久化提供便利．

## 使用

举例

Portainer的基本使用时

```
$ docker volume create portainer_data
$ docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer
```

首先：首选创建了一个数据卷

默认存在宿主机器中/var/lib/docker/volumes/目录，创建一个portainer\_data的目录，并将volume中的内容存储在名为 \_data的目录下.

```
/var/lib/docker/volumes/portainer_data
```

其次：

启动的时候通过挂在的方式使用-v参数进行挂在．平时开发当中多个挂在多个，也可以使用自己的目录进行挂载／

也可以通过docker volume inspect 命令获取该volume包括在其宿主机中改文件夹的位置等信息．

```
$ docker volume inspect portainer_data
[
    {
        "CreatedAt": "2018-08-13T09:55:43+08:00",
        "Driver": "local",
        "Labels": {},
        "Mountpoint": "/var/lib/docker/volumes/portainer_data/_data",
        "Name": "portainer_data",
        "Options": {},
        "Scope": "local"
    }
]
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docker.shujuwajue.com/docker-de-shi-yong/docker-shu-ju-juan.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
