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"
Logo

云原生社区为您提供最前沿的新闻资讯和知识内容

更多推荐