docker -v 选项只有一个字段

标签 docker

来自文档 docker volume

-v or --volume: Consists of three fields, separated by colon characters (:). The fields must be in the correct order, and the meaning of each field is not immediately obvious.



但我见过有人使用 -v 标志,它只包含一个字段:
docker run -v /data ubuntu

这个选项是什么意思?这是绑定(bind)挂载还是卷类型?

最佳答案

Docker 支持三种类型的卷,上面一种是匿名卷

匿名卷

An anonymous volume is useful for when you would rather have Docker handle where the files are stored. It can be difficult, however, to refer to the same volume over time when it is an anonymous volumes. To create an anonymous volume:


docker run -v /path/in/container ...

要找到此卷,您需要执行以下步骤来检查卷的长 ID。
docker inspect container_id

查看 Mounts然后运行
docker volume ls | grep volume_id

您将看到已创建卷。

主机卷

A host volume lives on the Docker host's filesystem and can be accessed from within the container. To create a host volume:


docker run -v /path/on/host:/path/in/container ...

命名卷

A named volume is similar to an anonymous volume. Docker manages where on disk the volume is created, but you give it a volume name. To create a named volume:


docker volume create somevolumename
docker run -v name:/path/in/container ...

docker-different-types-of-volumes

关于docker -v 选项只有一个字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59386122/

相关文章:

当 NODE_ENV=production 时,Typescript 编译失败(在 Docker 中)

docker-compose 设置环境变量不起作用

node.js - 无法将调试器附加到 Docker Node 8.9.x

kubernetes - 安装 Helm 图表稳定/MSSQL的Linux我得到 “pod has unbound PersistentVolumeClaims”

docker - 如何为docker创建覆盖网络,获取范围 "global"的错误数据存储未初始化

docker - 从 Hub 拉取私有(private) Docker 存储库时出现 404

docker - docker run --user 和 --group-add 参数的区别

node.js - 如何获取 Kubernetes 集群上所有正在运行的 POD

docker - alpine `apk` 是否有 ubuntu `apt` `--no-install-recommends` 等价物

docker - 卷 "mongo": hostPath type check failed:/mongo/data is not a directory 的 MountVolume.SetUp 失败