Docker Config.Volumes 是什么?

huangapple go评论67阅读模式
英文:

What is Docker Config.Volumes?

问题

我正在学习关于Docker卷的内容。我尝试使用docker -v选项来绑定到本地目录。之后,如果我使用docker inspect检查,只会在Mount中找到信息,而在Volumes中没有信息。

~ $ docker inspect --format='{{json .Config.Volumes }}{{json .Mounts}}' 6171e4550c47 | jq
null
[
  {
    "Type": "bind",
    "Source": "/Users/kyounghwan.choi/test",
    "Destination": "/opt/dir",
    "Mode": "",
    "RW": true,
    "Propagation": "rprivate"
  }
]

那么Volumes中的信息将在何时填充?

英文:

I am studying about docker volumes. I've tried using docker -v option to bind to a directory locally. After that, if i check with docker inspect, there is only information in Mount, but no information in Volumes.

~ $ docker inspect --format='{{json .Config.Volumes }}{{json .Mounts}}' 6171e4550c47 | jq
null
[
  {
    "Type": "bind",
    "Source": "/Users/kyounghwan.choi/test",
    "Destination": "/opt/dir",
    "Mode": "",
    "RW": true,
    "Propagation": "rprivate"
  }
]

When will the Volumes over there be filled?

答案1

得分: 0

Docker支持两种不同的持久性机制。您已创建了一个绑定挂载,使主机目录出现在容器中,但您尚未创建一个(命名)卷。这导致.Mounts字段显示容器中已经挂载了_某些东西_,但实际上没有_卷_本身已经被挂载。

也就是说,如果您没有将任何命名或匿名卷挂载到容器中,那么.Config.Volumes将始终为null,即使您已经绑定挂载了主机目录。

英文:

Docker supports two different persistence mechanisms. You have created a bind mount to cause a host directory to appear in the container, but you have not created a (named) volume. That causes the .Mounts filed to show something has been mounted in the container, but there's not a volume per se that you've mounted.

That is: if you haven't mounted any named or anonymous volumes into the container, then .Config.Volumes will always be null, even if you have bind-mounted host directories.

huangapple
  • 本文由 发表于 2023年3月12日 18:57:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/75712629.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定