docker volume create
创建一个卷,供容器使用以持久化存储数据。
如果未指定名称,Docker 会自动生成一个随机名称。
用法
docker volume create [OPTIONS] [VOLUME]选项
| 选项 | 默认值 | 描述 | | ---- | -- | | | --availability | active | (API 1.42+,Swarm 模式)集群卷的可用性状态(active、pause、drain) | | -d, --driver | local | 指定卷驱动程序名称 | | --group | — | (API 1.42+,Swarm 模式)集群卷所属的组 | | --label | — | 为卷设置元数据标签 | | --limit-bytes | — | (API 1.42+,Swarm 模式)集群卷的最小大小(字节) | | -o, --opt | — | 设置驱动程序特定的选项 | | --required-bytes | — | (API 1.42+,Swarm 模式)集群卷的最大大小(字节) | | --scope | single | (API 1.42+,Swarm 模式)集群卷的访问范围(single 或 multi) | | --secret | — | (API 1.42+,Swarm 模式)集群卷使用的密钥 | | --sharing | none | (API 1.42+,Swarm 模式)集群卷的共享策略(none、readonly、onewriter、all) | | --topology-preferred | — | (API 1.42+,Swarm 模式)集群卷优选的拓扑位置 | | --topology-required | — | (API 1.42+,Swarm 模式)集群卷必须满足的拓扑要求 | | --type | block | (API 1.42+,Swarm 模式)集群卷的访问类型(mount 或 block) |
注意:标记为 “Swarm” 的选项仅在使用支持集群卷(Cluster Volumes)的卷驱动且运行于 Swarm 模式下时有效。
多个容器可以挂载同一个卷,适用于需要共享数据的场景(例如一个容器写入,另一个读取)。
卷名称在同一驱动程序下必须唯一。若尝试使用已存在的名称创建新卷(即使驱动不同),将返回错误。但如果指定的卷名已在当前驱动中存在,Docker 会认为你希望复用该卷,不会报错。
某些卷驱动支持通过 -o 或 --opt 传递驱动专属选项。这些选项会直接透传给底层驱动。
内置的 local 驱动在 Windows 上不接受任何选项;在 Linux 和 Docker Desktop 上,它接受类似 Linux mount 命令的选项(如 type、device、o 等)。
最后更新于
这有帮助吗?