Docker Labels
Important
Labels serve as the metadata for a container image and, therefore, are IMPORTANT!
Open Container Initiative - Annotations
Sensia has adopted the label schema defined by the Open Container Initiative to ensure consistent naming conventions across all projects.
Include as many of the following se labels as possible in your Dockerfile:
- org.opencontainers.image.created - date and time on which the image was built
- org.opencontainers.image.authors - contact details of the people or organization responsible for the image (freeform string)
- org.opencontainers.image.url - URL to find more information on the image (string)
- org.opencontainers.image.documentation - URL to get documentation on the image (string)
- org.opencontainers.image.source - URL to get source code for building the image (string)
- org.opencontainers.image.version - version of the packaged software
- org.opencontainers.image.revision - source control revision identifier for the packaged software.
- org.opencontainers.image.vendor - name of the distributing entity, organization or individual.
- org.opencontainers.image.licenses - license(s) under which contained software is distributed.
- org.opencontainers.image.ref.name - name of the reference for a target (string).
- org.opencontainers.image.title - human-readable title of the image (string)
- org.opencontainers.image.description - human-readable description of the software packaged in the image (string)
If these are not sufficient, Sensia can define additional vendor-specific labels as needed.
Static vs. Dynamic
Most of the labels are static and can be hard-coded to predefined strings in the Dockerfile (for example: org.opencontainers.image.title).
Some are dynamic and need to be passed in as arguments to the Dockerfile (for example: org.opencontainers.image.created).
Example
Here are some sample snippets that show how labels are used:
docker build --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') -f dockerfile -t my-container-image .
FROM gcc:7
ARG BUILD_DATE
#Labels
LABEL org.opencontainers.image.title="AA Base Container Image" \
org.opencontainers.image.description="AA Base Container Image to be used in multi-stage builds" \
org.opencontainers.image.vendor="Sensia Global" \
org.opencontainers.image.authors="Vivek Chinta <vchinta1@sensiaglobal.com>" \
org.opencontainers.image.created="$BUILD_DATE"
Docker Inspect
The ‘docker inspect’ command can be used to dump the labels associated with a given image, shown here:
user@ubuntu1804vm:~/advapps/depSrc/docker-build$ docker inspect 1fe9682aeb60 | grep "Labels" -A 10
"Labels": {
"org.opencontainers.image.authors": "Vivek Chinta <vchinta1@sensiaglobal.com>",
"org.opencontainers.image.created": "2020-07-22T05:28:17Z",
"org.opencontainers.image.description": "AA Base Container Image to be used in multi-stage builds",
"org.opencontainers.image.title": "AA Base Container Image",
"org.opencontainers.image.vendor": "Sensia Global",
}
...