Custom tag and labels with docker plugin


I would like to define some custom labels in my image, which content would come from vars or commands.

        - org.opencontainers.image.source=$DRONE_REPO_LINK
        - org.opencontainers.image.created=$(date +%y%m%d-%H%M)
        - org.opencontainers.image.source=$DRONE_REPO_LINK
        - org.opencontainers.image.version=$appver

Is there a recommended way to do this, or should I modify the Dockerfile during a preceding step ?

I would like to define the image tag dinamically as well, like tags: $appver or even tags: $(magic sed in a file).
Is there a way to do this ?

Thanks !

I think this thread might be relevant for defining the image tag:

The reason the above example does not work is because the custom_labels is a Go string literal. It is not passed through a bash interpreter and therefore does not understand or evaluate bash syntax. As you mentioned you would probably need to modify the dockerfile during a preceding step.

However, with that being said, the docker plugin supports the opencontainers label specification and automatically adds these labels, by default. It works out-of-the-box with no additional configuration needed. You can find the relevant code here:

Thanks Brad, that works !

  • opencontainers labels out-of-the-box
  • custom label added to Dockerfile
  • custom tags in a .tags file at the root of the repo