Discover the Magic of Docker Labels! 🎉

Hello, fellow Sitecore Docker aficionados!

The other day, when I was creating a custom tooling Docker image for our project, I asked myself, “Wouldn’t it be nice if you could add information (like a description) to a Docker image, similar to the AssemblyInfo for (.NET) projects?”

Well, gather ’round, because I’m about to introduce you to a fantastic Docker feature that will add a dash of personality and clarity to your images: Docker Labels!

Labels: The Secret to Docker Image Charm

Labels are like the nametags at a party, except for your Docker objects. Whether it’s images, containers, volumes, or networks, labels let you sprinkle a bit of magic by attaching metadata to them. Think of labels as your Docker objects’ way of saying, “Hey, here’s who I am and what I’m all about!”

Why You’ll Love Docker Labels

Let’s talk real-world applications, shall we? Here’s why Docker labels are the life of the Docker party:

  • Organization Wizardry: Labels transform your Docker images into a well-organized gallery, making it easy to find the image you need based on its purpose, version, or any other criteria.
  • License Love: If you’ve got licensing details to share, labels are your best friends. They help you keep your Docker world legit by displaying licensing info right where it matters.
  • Interconnections Unveiled: In complex Docker setups, labels act as the storytellers, revealing how your containers, volumes, and networks are interconnected. No more mysteries!
  • Documentation Delight: Imagine labels as tiny scrolls of wisdom attached to your image, offering essential insights about its content, dependencies, and configuration. It’s like having a knowledgeable assistant!

Label Like a Pro!

Now, let’s get our hands dirty and add some labels to our tooling Docker image. It’s as fun as decorating a cake—without the mess! Here’s a peek at how it’s done:

# escape=` 
FROM mcr.microsoft.com/windows/nanoserver:ltsc2022 as scratch 
#I wish there was a scratch in the windows world 

COPY . .

LABEL name="YO YO Tooling"
LABEL version="v1.1"
LABEL description="This is a tooling image, it has all kind of wonderful goodies"
LABEL nodejs-version="v14.15.3"
LABEL nodejs-path="/tooling/nodejs"
LABEL sitecore-sxa-hotfix-version="595518-2"
LABEL sitecore-sxa-hotfix-path="/tooling/sxa-hotfixes/"
LABEL dianoga-version="v6.1.0"
LABEL dianoga-path="/tooling/dianoga/"

There you go! With these labels, your Docker image is now the life of the Docker party, flaunting its name, version, and a delightful description.

Unveiling the Label Magic

Now, how do you reveal the hidden treasures within your labeled image? It’s as simple as waving a wand (or typing a command):

docker image inspect --format='{{json .Config.Labels}}' yoyo-tooling

Voilà! Docker spills the beans, showing you all those wonderful labels you’ve added.

{
	"dianoga-path": "/tooling/dianoga",
	"dianoga-version": "v6.1.0",
	"nodejs-path": "/tooling/nodejs",
	"nodejs-version": "v14.15.3",
	"sitecore-sxa-hotfix-path": "/tooling/sxa-hotfixes/",
	"sitecore-sxa-hotfix-version": "595518-2",
	"description": "This is a tooling image, it has all kind of wonderful goodies",
	"name": "YO YO Tooling",
	"version": "1.1"
}

Unleash the JSON Magic with jq!

But wait, there’s more to this label party! We’re about to dive into the wonderful world of jq, the magic wand that lets you conjure information from your Docker Labels like a pro!

jq: Your Label Sorcerer 🧙‍♂️

jq is like the wizard’s spellbook for your JSON data. It allows you to extract, transform, and wield the power of your Docker Labels with elegance and finesse. Here’s how it works:

docker inspect yoyo-tooling | jq -r '.[0].Config.Labels.sitecore-sxa-hotfix-version'

Just like that, you’ve summoned the enchanting label value: 595518-2
It’s like discovering hidden treasure in your Docker image.

Unlock the Magic of jq ✨

And here’s the best part: jq is a tool you’d want in your tech toolbox. To make it yours, simply cast this spell:

choco install jq -y

With jq by your side, the labels in your Docker universe will reveal their secrets, making your Docker image management a breeze.

That’s all for now folks 😊


Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.