来自文档 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/