0
0
DockerConceptBeginner · 3 min read

What is LABEL in Dockerfile: Definition and Usage

The LABEL instruction in a Dockerfile adds metadata to an image as key-value pairs. This metadata helps describe the image, such as author, version, or purpose, making it easier to manage and search images.
⚙️

How It Works

The LABEL instruction works like putting a sticky note on a box to describe what's inside. When you build a Docker image, you can add labels that store information about the image, such as who made it or what version it is.

This metadata is stored inside the image and can be read later by tools or people to understand the image better without running it. Labels are simple text pairs, like key=value, and you can add many labels to one image.

💻

Example

This example shows how to add labels for author and version in a Dockerfile.

dockerfile
FROM alpine:3.18
LABEL maintainer="jane.doe@example.com" \
      version="1.0" \
      description="Simple Alpine Linux image with labels"
Output
docker image inspect <image_name> --format '{{json .Config.Labels}}' {"maintainer":"jane.doe@example.com","version":"1.0","description":"Simple Alpine Linux image with labels"}
🎯

When to Use

Use LABEL to add useful information about your Docker images. For example, you can include the author’s contact, version number, license, or a description of what the image does.

This helps teams keep track of images, especially when many images exist. It also helps automation tools find images by metadata or manage image versions.

Key Points

  • LABEL adds metadata as key-value pairs inside Docker images.
  • Labels help describe and organize images for humans and tools.
  • You can add multiple labels in one Dockerfile.
  • Labels do not affect the image’s functionality but improve management.

Key Takeaways

LABEL adds descriptive metadata to Docker images as key-value pairs.
Use LABEL to store author, version, and other useful info inside images.
Labels help teams and tools manage and identify images easily.
Multiple LABEL instructions can be used in one Dockerfile.
Labels do not change how the image runs but improve image documentation.