Bind path in singularity using container environment variable

878 Views Asked by At

I have a singularity container built with a scientific filesystem app. I run the container with singularity run --app myapp image.sif and, accordingly, I have the environment variable SCIF_APPDATA=/scif/data/myapp set inside the container.

I'd like to bind a path using this environment variable. Something like:

singularity run -B /my/path/on/host/:$SCIF_APPDATA/input/

Unfortunately this does not work. I didn't manage to make singularity use as a mount path the environment variable with its "internal" value.

I have to explicitly pass the value of the environment variable:

singularity run -B /my/path/on/host/:/scif/data/myapp/input

Does anybody know how to use container environment variables in bind paths?

1

There are 1 best solutions below

0
On BEST ANSWER

I don't think it is possible to directly use environment variables from inside the container in the bind statement. However, you can do it in two steps, first a call to singularity exec to get the value of the variable, then use it with singularity run:

SCIF_APPDATA=$(singularity exec ascisoftApp.sif bash -c "echo \$SCIF_APPDATA")
singularity run -B /my/path/on/host/:$SCIF_APPDATA/input/ ...

Don't forget the backslash to escape the $ in the echo command.

Note: Not sure why but it doesn't work for me when I directly use echo, hence the wrapping with bash -c.