简体   繁体   English

Docker 卷由 Dockerfile 或 Docker-compose 文件创建

[英]Docker volume created by what Dockerfile or Docker-compose file

How can we find out what Docker volume was created by what dockerfile or Docker-compose file please?我们如何找出 Docker 卷是由 dockerfile 或 Docker-compose 文件创建的?

Assuming that you are talking about docker-compose files (not about Dockerfiles because you can't specify volumes there), the best thing that you can do is to create a named volume with an appropriate name so that you know what kind of data it stores.假设您正在谈论 docker-compose 文件(不是关于 Dockerfiles,因为您无法在其中指定卷),您可以做的最好的事情是创建一个具有适当名称的命名卷,以便您知道它存储什么样的数据。

You can't find out what volume belongs to which docker-compose file as that file might not even exist anymore while volumes are meant to be persistent, and not tight to a lifecycle of a container.您无法找出哪个卷属于哪个 docker-compose 文件,因为该文件甚至可能不再存在,而卷应该是持久的,并且与容器的生命周期不紧密。 Each container has its own read-write filesystem layer for that purpose.为此,每个容器都有自己的读写文件系统层。

Here is an example of what you can do.这是您可以执行的操作的示例。

version: "3"
services:
    db:
        image: mongo
        volumes:
            - mongo-data:/data/db

volumes:
    mongo-data:

Now when you do docker volume ls you will see something like.现在,当您执行docker volume ls时,您会看到类似的内容。

local               tmp_mongo-data

That tmp is added by docker-compose but the rest of the name tells me that the purpose of the volume is to store some data for mongo database (not very specific in this case but you can be more specific if you want to).tmp是由 docker-compose 添加的,但名称的 rest 告诉我该卷的目的是为 mongo 数据库存储一些数据(在这种情况下不是很具体,但如果您愿意,可以更具体)。

It is better to think about volumes as a standalone components which can be reused by many, instead of a resource tight to a specific container (or to a specific docker-compose file).最好将卷视为可以被许多人重用的独立组件,而不是将资源紧贴到特定容器(或特定 docker-compose 文件)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM