Adding a label to a named volume in docker-compose
·
Answer a question
I would like to add a label to some volumes created with docker-compose, so that I can filter easier when pruning
If I understand the documentation correctly this should work by declaring it in the docker-compose.yml
volumes:
myVolume:
labels:
- "ch.example.label=foo"
However, if I inspect the created volume, no such label exists:
docker volume inspect myVolume
[
{
"CreatedAt": "2021-10-28T09:31:55+02:00",
"Driver": "local",
"Labels": {},
"Mountpoint": "/var/lib/docker/volumes/myVolume/_data",
"Name": "myVolume",
"Options": {},
"Scope": "local"
}
]
If I create the volume directly with docker volume create --label... it works as expected
Answers
Once a volume is created you cannot add a label to it. You must delete the volume, add the label to your docker-compose file, and run docker-compose up again.
volumes:
myVolume:
labels:
ch.example.label: "foo"
更多推荐
所有评论(0)