Kritim Yantra
Apr 25, 2025
When working with Docker, it's easy to focus on things like containers, Dockerfiles, and registries. But there's one powerful feature that often gets overlooked — Docker image labels.
In this blog, we’ll explore:
Let’s dive in!
Docker labels are key-value pairs that you attach to your images (or containers) to store metadata.
They don’t affect how the image runs, but they help describe the image for both humans and tools.
Think of labels as sticky notes that describe the who, what, and why of your Docker image.
Here are some great reasons to use Docker labels:
Labels help describe:
DevOps tools and CI/CD pipelines can search or filter images based on labels. For example: find all images maintained by a specific team.
Labels can be used by:
This makes automation and reporting much easier.
Following best practices like the OpenContainers Label Schema helps with consistency and standards.
You can add labels in your Dockerfile
using the LABEL
instruction:
FROM node:18
LABEL maintainer="you@example.com"
LABEL version="1.0"
LABEL description="My awesome Node.js app"
LABEL org.opencontainers.image.source="https://github.com/yourname/yourrepo"
Each label is written as:
LABEL key="value"
You can also add multiple labels in one line:
LABEL maintainer="you@example.com" version="1.0" environment="production"
After building your image, you can view its labels using:
docker inspect your-image-name
Look under the "Labels"
section in the JSON output.
Or if you just want the labels:
docker inspect -f '{{json .Config.Labels }}' your-image-name
Here are some common and useful labels:
Label | Purpose |
---|---|
maintainer |
Who built/owns the image |
version |
Image version |
description |
What this image does |
org.opencontainers.image.title |
Human-readable title |
org.opencontainers.image.source |
Source repo URL |
org.opencontainers.image.licenses |
License (e.g. MIT) |
org.opencontainers.image.created |
Build time |
You can customize these labels based on your organization or project needs.
For example, in GitHub Actions you can do something like:
- name: Build Docker image
run: |
docker build \
--label "org.opencontainers.image.revision=${{ github.sha }}" \
--label "org.opencontainers.image.created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \
-t myapp:${{ github.sha }} .
Docker labels are simple but powerful. They help you manage, document, and automate your Docker images — especially as your project or team grows.
They don’t change how your image works, but they change how you manage it in the real world.
Add labels to your Docker images today, and your future self (or team) will thank you!
No comments yet. Be the first to comment!
Please log in to post a comment:
Sign in with Google