3

I have a BASH pipeline which at a point runs a Singularity container with singularity exec as follows:

singularity exec --bind `pwd`:/folder --bind $d:/results <image>.sif <tool_command> -i /folder/<file>.fastq -v /results/<output>/<file>.vcf -r /folder/<reference>.fna -s <vcf_sample_name> -j 24 -t 24 -o /results/<output_file_suffix>

Since I'm running multiple experiments at once with an array, I'm redefining the experiments with an environment variable that I wish to add to the <output_file_suffix>; it works for all the steps of the pipeline but Singularity seems it's unable to see the variable(s) I'm defining in my script...

Does anyone have any advice on how to do so? I looked up a bit but the --env does not seem to be working. Thanks in advance!

0

1 Answer 1

9

The point of Singularity is that it runs software inside a container. The container is isolated from its host so that it works the same everywhere. The behavior of the container does not depend on things like the software installed on the host, the files available on the host or the environment variables on the host.

You pass --bind HOST_PATH:CONTAINER_PATH to singularity exec to make a specific directory of the host accessible inside the container. Somewhat similarly, use --env NAME=VALUE to make an environment variable accessible inside the container. It's done a bit differently because the value doesn't have to be the same as the host. To give an environment variable the same value as the host, when invoking singularity from a shell script, use --env FOO="$FOO". Note the double quotes around the value, otherwise it won't work if the value contains spaces or other special characters.

The documentation of Singularity's command line is a bit scarce. Singularity wraps around Docker and you can sometimes find more information in its documentation, for example singularity exec --env is similar to docker run --env and the Docker documentation has more information. But beware that Singularity is not a straight wrapper, so not all Docker options exist or behave in the same way.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.