What is LABEL in Dockerfile: Definition and Usage
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.
FROM alpine:3.18 LABEL 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.