Reputation: 43
How can we find out what Docker volume was created by what dockerfile or Docker-compose file please?
Upvotes: 0
Views: 62
Reputation: 14512
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.
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. 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.
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).
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).
Upvotes: 2