泊坞窗撰写卷类型-绑定与卷 [英] docker compose volume type - bind vs volume
问题描述
TLDR
在 docker-compose
中,两者之间有什么区别
In docker-compose
, whats the difference between
volumes:
- type: volume
source: mydata
target: /data
和
volumes:
- type: bind
source: mydata
target: /data
?
问题很长:
在 docker-compose
文件中指定 volumes
选项时,可以使用
When you specify the volumes
option in your docker-compose
file, you can use the long-syntax style
根据文档, type
选项接受3个不同的值: volume
, bind
和 tmpfs
:
According to the docs, the type
option accepts 3 different values: volume
, bind
and tmpfs
:
我了解 tmpfs
选项-但是我在文档中找不到关于其他两个选项之间的区别的任何参考: bind
和 volume
,有人可以启发我吗?
But I fail to find any reference in the docs about the difference between the other 2 options: bind
and volume
, could someone enlighten me about that?
推荐答案
When bind mounts are files coming from your host machine, volumes are something more like the nas of docker.
- 绑定装载是从主机(运行docker守护程序的主机)装载到容器上的文件.
- 卷就像完全由docker管理的存储空间.
在文献中,您会发现两种类型的卷:- 命名卷(您提供其名称)
- 匿名卷(通常来自docker的UUID名称,例如您可以在容器或未标记的图像上找到它们)
这些卷带有它们自己的 docker命令的集合.您也可以通过
Those volumes come with their own set of docker commands; you can also consult this list via
docker volume --help
您可以通过以下方式查看现有卷
You can see your existing volumes via
docker volume ls
您可以通过以下方式创建命名卷
You can create a named volume via
docker volume create my_named_volume
但是您也可以通过
docker-compose
文件version: "3.3" services: mysql: image: mysql volumes: - type: volume source: db-data target: /var/lib/mysql/data volumes: db-data:
这是说的部分,请泊坞窗,在容器目录/var/lib/mysql/data 顶部>上将名为 db-data 的卷装载到我>
Where this is the part saying please docker, mount me the volume named db-data on top of the container directory /var/lib/mysql/data
- type: volume source: db-data target: /var/lib/mysql/data
这是对docker 说的部分,请为我创建一个名为 db-data
And this is the part saying to docker please create me a volume named db-data
volumes: db-data:
有关三种安装类型的Docker文档:
Docker documentation about the three mount types:
- https://docs.docker.com/storage/bind-mounts/
- https://docs.docker.com/storage/volumes/
- https://docs.docker.com/storage/tmpfs/
这篇关于泊坞窗撰写卷类型-绑定与卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!