Docker – The LABEL instruction

How to turn off IE enhanced security on Windows Server 2019

The LABEL instruction is a way to add metadata to your Docker image. This instruction adds embedded key-value pairs to the image. The LABEL instruction adds a zero-byte-sized layer to the image when it is created. An image can have more than one LABEL, and each LABEL instruction can provide one or more LABELs. The most common use for the LABEL instruction is to provide information about the image maintainer. This data used to have its own instruction. See the following tip box about the now-deprecated MAINTAINER instruction. Here are some examples of valid LABEL instructions:

# LABEL instruction syntax
# LABEL <key>=<value> <key>=<value> <key>=<value> ...
LABEL maintainer="Earl Waud <>"
LABEL "description"="My development Ubuntu image"
LABEL version="1.0"
LABEL label1="value1" \
 label2="value2" \
LABEL my-multi-line-label="Labels can span \
more than one line in a Dockerfile."
LABEL support-email="" support-phone="(123) 456-7890"

The LABEL instruction is one of the instructions that can be used multiple times in a Dockerfile. You will learn later that some instructions that can be used multiple times will result in only the last use being significant, thus ignoring all previous uses. The LABEL instruction is different. Every use of the LABEL instruction adds an additional label to the resulting image. However, if two or more uses of LABEL have the same key, the label will get the value provided in the last matching LABEL instruction. That looks like this:

# earlier in the Dockerfile
LABEL version="1.0"
# later in the Dockerfile...
LABEL version="2.0"
# The Docker image metadata will show version="2.0"

It is important to know that the base image specified in your FROM instruction may include labels created with the LABEL instruction and that they will automatically be included in the metadata of the image you are building. If a LABEL instruction in your Dockerfile uses the same key as a LABEL instruction used in the FROM image’s Dockerfile, your (later) value will override the one in the FROM image. You can view all of the labels for an image by using the inspect command:

The MAINTAINER instruction
There is a Dockerfile instruction specifically for providing the info about the image maintainer, however, this instruction has been deprecated. Still, you will probably see it used in a Dockerfile at some point. The syntax goes like this: "maintainer": "Earl Waud <>".

Comments are closed.