Singularity containers support environment variables and labels that can be added by user during the bootstrap process.


If you are importing a Docker container, the environment will be imported as well. If you want to define custom environment variables in your bootstrap recipe file Singularity you can do that like this

From: ubuntu:latest

    export VARIABLE_NAME

Forget something, or need a variable defined at runtime? You can set any variable you want inside the container by prefixing it with “SINGULARITYENV_”. It will be transposed automatically and the prefix will be stripped. For example, let’s say we want to set the variable HELLO to have value WORLD. We can do that as follows:

$ SINGULARITYENV_HELLO=WORLD singularity exec -e centos7.img env

Notice the -e? That is the argument (or --cleanenv) that specifies that we want to remove the host environment from the container. If we remove the -e, we will still pass forward HELLO=WORLD, and the list shown above, but we will also pass forward all the other environment variables from the host. Here is a command to directly echo the variable we define:

$echo 'echo $HELLO' | SINGULARITYENV_HELLO=WORLD singularity exec centos7.img /bin/sh

If you want to look at the environment inside a container, you can look inside the metadata env folder as follows:

singularity exec centos7.img ls /.singularity.d/env

The variables in are a set of defaults set upon container creation, and the come from a Docker import.

singularity exec centos7.img cat /.singularity.d/env/
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin


Your container stores metadata about it’s build, along with Docker labels. You can see the data as follows:

singularity exec centos7.img cat /.singularity.d/labels.json
{ "name": 
      "CentOS Base Image", 
       "build-date": "20170315", 
       "vendor": "CentOS", 
       "license": "GPLv2"

You can add custom labels to your container in a bootstrap file:

Bootstrap: docker
From: ubuntu: latest


AUTHOR Vanessasaur