英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论