From the course: Docker: Build and Optimize Docker Images
Labeling Docker images - Docker Tutorial
From the course: Docker: Build and Optimize Docker Images
Labeling Docker images
- [Narrator] A simple but powerful way to keep your docker images organized and informative is with labels. Think of labels as tiny sticky notes. They're key value pairs you can add to an image that don't change how it runs, but pack in a world of useful info. Need to track who built the image? When it was created? Or link back to the source repo? With labels, you are in control of your metadata making automation, documentation, and tooling a breeze. One of the most common ways to assign labels is in the docker file. Here, I have the docker file open from our exercise files. Let's add a comment before the command instruction for add labels. On the next line, type label in all caps, we're going to add the most commonly used labels from the Open Container Initiative or OCI. First type org.open containers.image.title equals, and then in quotes, no dap, and then a slash to continue. on the next line. Here, type org.open containers.image.version equals, and then in quotes two 3.1. You can either use a slash like we've done here to combine multiple labels into one label instruction, or you can have separate lines each with the label instruction. It's up to you, there's no difference in the end. The labels are created when you build the image using the docker build command, open a terminal and type docker build, T flag, and we can use the image inversion that we build in the previous video for docker image demo 2.3.0.1, and then we'll add a period at the end. You can also apply labels dynamically at build time, using the CLI press the up arrow key to bring up the last command run. Let's remove the period and add two dashes and the word label. The label goes in quotes, and we can use calm.example. Project.environment equals staging. This is a common naming convention for labels. You can prefix your labels using the domain or project name and environment. And then let's add a second label using another common OCI label. Org.open containers.image.authors, and I'll set mine to my name. You can use your name here. This label makes it easy to determine who's worked on a specific image in case you need to contact them. Another way to add labels to your images is in the compose file. I have the compose file open for our project, and I'm going to add labels in the build section under the build target on line seven. On the next line, I'll put a dash because labels are in list format, then I'll add another popular label. Org.open containers.image.licenses equals MIT. This label helps to keep track of license information to ensure it's up to date and the image is compliant. I've also added the image and version on line three. This includes the name of the image, which is Docker Image Demo, and then the version, which is 2.3.1. Now we can build our image using the command Docker Compose build. In the next video, we'll discuss how to view and search for image labels.
Contents
-
-
-
-
(Locked)
Why image organization matters2m 45s
-
(Locked)
Tagging Docker images4m 10s
-
Labeling Docker images3m 54s
-
(Locked)
Working with tags and labels2m 28s
-
(Locked)
Working with an image repository4m 12s
-
(Locked)
Challenge: Tagging and labeling Docker images1m 9s
-
(Locked)
Solution: Tagging and labeling Docker images3m 17s
-
(Locked)
-
-
-
-
-