How to pass the host environment variables to the container or override the $PATH within the container?

4,018 views
Skip to first unread message

Samy

unread,
May 17, 2019, 7:48:26 PM5/17/19
to singularity
Hello,

I'm using singularity version 2.6.

I basically have containers that dependent on the compiler and mpi that exist on the host to run on.  I'm thinking about just setting up the $PATH inside the container.

The path prior to modifying it looks like:
 bash-4.2$ singularity exec lammps..simg echo $PATH/usr/local/go/bin:/bin:.:/usr/bin:/usr/local/bin:/usr/sbin:/sbin:/nfs/pdx/home/...


Then i set the SINGULARITYENV_PATH as shown here: https://www.sylabs.io/guides/3.0/user-guide/environment_and_metadata.html
SINGULARITYENV_PATH=/opt/intel/compilers_and_libraries_2019.3.199/linux/tbb/bin:/opt/intel/compilers_and_libraries_2019.4.227/linux/bin/intel64:/opt/intel/compilers_and_libraries_2019.4.227/linux/mpi/.....

But the path still doesn't update/work withing the container:
bash-4.2$ singularity exec lammps..simg echo $PATH/usr/local/go/bin:/bin:.:/usr/bin:/usr/local/bin:/usr/sbin:/sbin:/nfs/pdx/home/...

Any advise please? IF setting up the SINGULARITYENV_PATH is not an option, do you have any other recommendations ?

Thank you,

David Godlove

unread,
May 17, 2019, 10:48:48 PM5/17/19
to singularity
That has more to do with the container itself than the version of Singularity.  Is it possible to rebuild these containers with 2.6.1?  

--
You received this message because you are subscribed to the Google Groups "singularity" group.
To unsubscribe from this group and stop receiving emails from it, send an email to singularity...@lbl.gov.
To view this discussion on the web visit https://groups.google.com/a/lbl.gov/d/msgid/singularity/514bb438-f1ea-42bd-91fe-46741855f5ea%40lbl.gov.

Samy

unread,
May 19, 2019, 5:13:33 PM5/19/19
to singularity
That is the version im using already:

bash-4.2$ singularity --version
2.6.1-dist


On Friday, May 17, 2019 at 7:48:48 PM UTC-7, David Godlove wrote:
That has more to do with the container itself than the version of Singularity.  Is it possible to rebuild these containers with 2.6.1?  

On Fri, May 17, 2019 at 5:48 PM Samy <smahan...@gmail.com> wrote:
Hello,

I'm using singularity version 2.6.

I basically have containers that dependent on the compiler and mpi that exist on the host to run on.  I'm thinking about just setting up the $PATH inside the container.

The path prior to modifying it looks like:
 bash-4.2$ singularity exec lammps..simg echo $PATH/usr/local/go/bin:/bin:.:/usr/bin:/usr/local/bin:/usr/sbin:/sbin:/nfs/pdx/home/...


Then i set the SINGULARITYENV_PATH as shown here: https://www.sylabs.io/guides/3.0/user-guide/environment_and_metadata.html
SINGULARITYENV_PATH=/opt/intel/compilers_and_libraries_2019.3.199/linux/tbb/bin:/opt/intel/compilers_and_libraries_2019.4.227/linux/bin/intel64:/opt/intel/compilers_and_libraries_2019.4.227/linux/mpi/.....

But the path still doesn't update/work withing the container:
bash-4.2$ singularity exec lammps..simg echo $PATH/usr/local/go/bin:/bin:.:/usr/bin:/usr/local/bin:/usr/sbin:/sbin:/nfs/pdx/home/...

Any advise please? IF setting up the SINGULARITYENV_PATH is not an option, do you have any other recommendations ?

Thank you,

--
You received this message because you are subscribed to the Google Groups "singularity" group.
To unsubscribe from this group and stop receiving emails from it, send an email to singu...@lbl.gov.

Robert Lugg

unread,
Jul 15, 2019, 10:38:45 AM7/15/19
to singularity
Hi Samy, did you have any luck with this?  I do not know but do you need to have those host directories also bound to within the container?

Samy

unread,
Jul 16, 2019, 4:23:25 PM7/16/19
to singularity
Hello Robert,

Yes. I had to pass in my LD_LIBRARY_PATH from the host to the container to get it to work like this:
        $ export SINGULARITYENV_LD_LIBRARY_PATH=$LD_LIBRARY_PATH.

This will override my $LD_LIBARRY_PATH inside the container. So, i had to setup this up inside the container to get it to work:
       $ export LD_LIBRARY_PATH=/.singularity.d/libs:$LD_LIBRARY_PATH 

Here where i found out about these envs: https://singularity.lbl.gov/docs-environment-metadata

Rémy Dernat

unread,
Jul 17, 2019, 5:40:25 AM7/17/19
to singu...@lbl.gov
Hi,

The PATH variable maybe overriden during runtime. You should consider writing to/append to an environment file for Singularity instead:

This old doc works for Singularity 2.x

Best regards,
Rémy.


To unsubscribe from this group and stop receiving emails from it, send an email to singularity...@lbl.gov.
To view this discussion on the web visit https://groups.google.com/a/lbl.gov/d/msgid/singularity/ab491828-f63f-4e75-aac5-bf5d574e6239%40lbl.gov.

Samy

unread,
Jul 17, 2019, 11:04:09 AM7/17/19
to singularity
THe append works only with PATH. I needed to change the LD_LIBRARY_PATH inside the container.


On Wednesday, July 17, 2019 at 2:40:25 AM UTC-7, Rémy Dernat wrote:
Hi,

The PATH variable maybe overriden during runtime. You should consider writing to/append to an environment file for Singularity instead:

This old doc works for Singularity 2.x

Best regards,
Rémy.


Thomas Hartmann

unread,
Jul 17, 2019, 12:09:34 PM7/17/19
to singu...@lbl.gov
Hi Samy,

to overwrite an environment variable, you could force it by modifying
Singularity's container actions.
I.e.,
use a temporary variable to track the host's LD_LIBRARY_PATH and add an
export to an action script for example, which replaces the
LD_LIBRARY_PATH in the container's context with the temporary one.

For the shell action, something like

%post
sed -i '1iexport LD_LIBRARY_PATH=${MYOUTERPATH}'
/.singularity.d/actions/shell

should work when building the container (same for exec, run, start,test)

before running your container, you would then have to copy your path
into the tmp var

SINGULARITYENV_MYOUTERPATH=${LD_LIBRARY_PATH}
singularity shell your.container

However, that would require, that your container is more or less
equivalent with your host environment - else all your shared libraries
will clash.

Cheers,
Thomas

On 17/07/2019 17.04, Samy wrote:
> THe append works only with PATH. I needed to change the LD_LIBRARY_PATH
> inside the container.
>
> On Wednesday, July 17, 2019 at 2:40:25 AM UTC-7, Rémy Dernat wrote:
>
> Hi,
>
> The PATH variable maybe overriden during runtime. You should
> consider writing to/append to an environment file for Singularity
> instead:
> https://singularity.lbl.gov/docs-environment-metadata
> <https://singularity.lbl.gov/docs-environment-metadata>
>
> This old doc works for Singularity 2.x
>
> Best regards,
> Rémy.
>
>
> Le mar. 16 juil. 2019 à 22:23, Samy <smahan...@gmail.com
> <javascript:>> a écrit :
> <https://groups.google.com/a/lbl.gov/d/msgid/singularity/514bb438-f1ea-42bd-91fe-46741855f5ea%40lbl.gov?utm_medium=email&utm_source=footer>.
>
> --
> You received this message because you are subscribed to the
> Google Groups "singularity" group.
> To unsubscribe from this group and stop receiving emails from
> it, send an email to singu...@lbl.gov <javascript:>.
> To view this discussion on the web visit
> https://groups.google.com/a/lbl.gov/d/msgid/singularity/ab491828-f63f-4e75-aac5-bf5d574e6239%40lbl.gov
> <https://groups.google.com/a/lbl.gov/d/msgid/singularity/ab491828-f63f-4e75-aac5-bf5d574e6239%40lbl.gov?utm_medium=email&utm_source=footer>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "singularity" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to singularity...@lbl.gov
> <mailto:singularity...@lbl.gov>.
> To view this discussion on the web visit
> https://groups.google.com/a/lbl.gov/d/msgid/singularity/85f52304-7857-462f-ac7c-aba5bc1f9fd3%40lbl.gov
> <https://groups.google.com/a/lbl.gov/d/msgid/singularity/85f52304-7857-462f-ac7c-aba5bc1f9fd3%40lbl.gov?utm_medium=email&utm_source=footer>.

Justin Cook

unread,
Aug 13, 2019, 10:46:05 AM8/13/19
to singularity
Samy,

The preferred way to do this would be to set `SINGULARITYENV_LD_LIBRARY_PATH` to the value you want to see in the container.

Example:

```
$ singularity exec busybox_latest.sif printenv LD_LIBRARY_PATH
/.singularity.d/libs

$ env SINGULARITYENV_LD_LIBRARY_PATH=/path/to/libs singularity exec busybox_latest.sif printenv LD_LIBRARY_PATH
/path/to/libs:/.singularity.d/libs
```
Reply all
Reply to author
Forward
0 new messages