Dockerfile Labels
Overview
What I want to achieve is dynamically defining some values and passing them to the docker build to populate labels in the container. This to be used in a CICD pipeline.
Using Arguments
Here is a sample of dockerfile to build a hugo site.
ARG
represent arguments a default value can be set to use when no values are provided during the build of the image. It s important to have the Global definition at the top, then to have the definition between the FROM and the LABEL.
LABEL
is used to define key value pairs.
|
|
The above script can be run with the following command :
|
|
Standard Labels
During my research I have found out that some label keys were already used and suggested. (org.opencontainers.image
and org.label-schema
prefixes)
org.opencontainers.image prefix | org.label-schema prefix | Description |
---|---|---|
created | build-date | date and time on which the image was built |
authors | - | contact details of the people or organization responsible for the image |
url | url | URL to get documentation on the image |
documentation | usage | URL to get documentation on the image |
source | vcs-url | URL to get source code for building the image |
version | version | version of the packaged software, MAY match a label or tag in the source code repository |
vendor | vendor | Name of the distributing entity, organization or individual |
licenses | - | License(s) under which contained software is distributed as an SPDX License Expression |
ref.name | - | Name of the reference for a target (string). SHOULD only be considered valid when on descriptors on index.json within image layout. Character set of the value SHOULD conform to alphanum of A-Za-z0-9 and separator set of -.:@/+ The reference must match the following grammar: ref ::= component ("/" component)* component ::= alphanum (separator alphanum)* alphanum ::= [A-Za-z0-9]+ separator ::= [-.:@+] |
title | name | Human-readable title of the image |
description | description | Human-readable description of the software packaged in the image |
- | schema-version | |
- | docker.*, rkt.* |