Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the actual use of labels in docker-compose

I was reading docker-compose tutorials and want to understand more about labels I read that they can be used to store metadata. Is labels useful just to store metadata or Are there any other significant uses? Please help me to understand this more.

like image 323
a8989 Avatar asked Aug 16 '18 09:08

a8989


People also ask

What is the use of Docker labels?

Labels are used in Dockerfile to help organize your Docker Images. Labels are key-value pairs and simply adds custom metadata to your Docker Images. Some key points associated with the LABEL instructions are as follows: To include spaces inside a label, you can use quotes.

What is labels in Docker compose?

Labels are a mechanism for applying metadata to Docker objects, including: Images. Containers. Local daemons. Volumes.

How do you label an image with Docker Build?

One way to add a label to a Docker image is by adding the LABEL instruction to a Dockerfile , while another way is by adding them to the docker build command using the --label flag. The second way is useful when you need to add labels, like git-commit or build-url , dynamically, during the build pipeline.


1 Answers

Labels are basically for metadata and don't have any specific effect as long as you aren't using them. So there are some use cases where labels come in handy:

  • You want to filter the list of running containers based on some predefined criteria, so you could run docker ps --filter "label=customer=customer1"
  • Labels can also be used for monitoring, so the monitoring system can read them and attach them to the metrics it gathers (e.g. when running cAdvisor)
  • third-party tools can make use of labels to act on them automatically. For example see the docs of the traefik proxy that uses docker labels to configure routing of dns names to containers (or more specifically to services)

So there is no direct implication of labels by docker but there are many use cases where this generic concept is a nice way to allow extending the technology.

like image 158
Andreas Jägle Avatar answered Sep 28 '22 02:09

Andreas Jägle