Here is a quick snippet for how to dynamically add labels to your Singularity Container at build time, which are then exposed when you inspect it. First, here is the recipe:

We are basically copying the Python helpers from Singularity into the image (in %setup), and then using them in %post to add a dynamic label with key AVOCADOS and value NOMNOM. Note that this is using Singularity version 2.4. To build our image from this recipe, we can do that in one line:

sudo singularity build labels.simg Singularity.labels


And now we can inspect the container to see the labels:

singularity inspect labels.simg
{
"org.label-schema.usage.singularity.deffile.bootstrap": "docker",
"org.label-schema.usage.singularity.deffile": "Singularity.labels",
"org.label-schema.schema-version": "1.0",
"org.label-schema.build-size": "1308MB",
"org.label-schema.usage.singularity.deffile.from": "ubuntu:16.04",
"org.label-schema.build-date": "2017-11-03T09:29:43-07:00",