Skip to contents

Adds a LABEL instruction to include metadata in the Docker image.

Usage

dfi_label(dockerfile, ...)

Arguments

dockerfile

A dockerfile object

...

Named labels as key-value pairs

Value

An updated dockerfile object with the LABEL instruction added

Details

Labels are key-value pairs that add metadata to your image. They can be used to organize images, record licensing information, annotate build information, or help with image automation.

Common label conventions include:

  • maintainer: The person responsible for the image

  • org.opencontainers.image.authors: Image authors

  • org.opencontainers.image.version: Version of the packaged software

  • org.opencontainers.image.source: URL to the source code

See also

dfi_maintainer() for the deprecated maintainer instruction & Official Docker LABEL documentation

Other dockerfile instruction functions: dfi_add(), dfi_arg(), dfi_cmd(), dfi_copy(), dfi_entrypoint(), dfi_env(), dfi_expose(), dfi_from(), dfi_healthcheck(), dfi_maintainer(), dfi_onbuild(), dfi_run(), dfi_shell(), dfi_stopsignal(), dfi_user(), dfi_volume(), dfi_workdir()

Examples

# Add a single label
df <- dockerfile() |>
  dfi_from("rocker/r-ver:4.4.0") |>
  dfi_label(maintainer = "user@example.com")
df
#> FROM rocker/r-ver:4.4.0
#> LABEL maintainer="user@example.com" 

# Add multiple labels
df <- dockerfile() |>
  dfi_from("rocker/r-ver:4.4.0") |>
  dfi_label(
    maintainer = "user@example.com",
    version = "1.0.0",
    description = "Example R application",
    org.opencontainers.image.source = "https://github.com/user/repo"
  )
df
#> FROM rocker/r-ver:4.4.0
#> LABEL maintainer="user@example.com" version="1.0.0" description="Example R application" org.opencontainers.image.source="https://github.com/user/repo"