weixin_39889642
weixin_39889642
2020-11-29 10:22

Envvar $SINGULARITY_BIND is no longer available from within the container

Version of Singularity: 3.6.3

Expected behavior

If I define SINGULARITY_BIND in my terminal environment and then launch a container, I would expect this envvar to be available from within the container.

Actual behavior

All other envvars are available from within the container, but not SINGULARITY_BIND:


export SINGULARITY_BIND=/archive,/sandbox,/scratch
module load singularity/3.6.3
singularity shell myContainer.sif
Singularity> echo $SINGULARITY_BIND
Singularity> ls /
archive  dev          home   media  proc  sandbox  singularity  tmp
bin  environment  lib    mnt    root  sbin     srv      usr
boot     etc          lib64  opt    run   scratch  sys      var
Singularity> echo $HOME
/home/myuser
Singularity> exit

This used to work fine in the previous version we used: Singularity version 3.2.1

bash
# PREVIOUSLY
export SINGULARITY_BIND=/archive,/sandbox,/scratch
module load singularity/3.2.1
singularity shell  myContainer.sif
Singularity myContainer.sif:~> echo $SINGULARITY_BIND
/archive,/sandbox,/scratch
Singularity myContainer.sif:~> ls /
archive  dev          home   media  proc  sandbox  singularity  tmp
bin  environment  lib    mnt    root  sbin     srv      usr
boot     etc          lib64  opt    run   scratch  sys      var
Singularity myContainer.sif:~> echo $HOME
/home/myuser
Singularity myContainer.sif:~> exit

Workaround

I can access the values of $SINGULARITY_BIND within the container by passing them to an envvar with another name, say $WORKAROUND_SINGULARITY_BIND.

What OS/distro are you running


$ cat /etc/os-release
NAME="Scientific Linux"
VERSION="7.8 (Nitrogen)"
ID="scientific"
ID_LIKE="rhel centos fedora"
VERSION_ID="7.8"
PRETTY_NAME="Scientific Linux 7.8 (Nitrogen)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:scientificlinux:scientificlinux:7.8:GA"
HOME_URL="http://www.scientificlinux.org//"
BUG_REPORT_URL="mailto:scientific-linux-devel.fnal.gov"

REDHAT_BUGZILLA_PRODUCT="Scientific Linux 7"
REDHAT_BUGZILLA_PRODUCT_VERSION=7.8
REDHAT_SUPPORT_PRODUCT="Scientific Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="7.8"

How did you install Singularity

From source, as follows:


wget https://golang.org/dl/go1.15.2.linux-amd64.tar.gz
cd /cm/shared/apps/go/
ll
mkdir 1.15.2
cd 1.15.2/
wget https://golang.org/dl/go1.15.2.linux-amd64.tar.gz
 tar -xzf go1.15.2.linux-amd64.tar.gz 
ll go/
ll
rm go1.15.2.linux-amd64.tar.gz 
mv -R go/* .
mv -r go/* .
mv go/* .
ll
rm -rf go
ll
cp /cm/shared/modulefiles/go/1.12.5 /cm/shared/modulefiles/go/1.15.2
vi /cm/shared/modulefiles/go/1.15.2
module add  go/1.15.2 
ll /root/go/
export GOPATH=/root/go
go get -u github.com/golang/dep/cmd/dep
mkdir -p $GOPATH/src/github.com/sylabs
ll /root/go/
ll /root/go/src/github.com/sylabs/
cd /root/go/src/github.com/sylabs
ll
wget https://github.com/hpcng/singularity/releases/download/v3.6.3/singularity-3.6.3.tar.gz
tar -xzf singularity-3.6.3.tar.gz 
ll
ll singularity/
rm -rf singularity
tar -xzf singularity-3.6.3.tar.gz 
ll
mkdir /cm/shared/apps/singularity/3.6.3
cd singularity
./mconfig --prefix=/cm/shared/apps/singularity/3.6.3
make -C ./builddir
make -C ./builddir install
cp /cm/shared/modulefiles/singularity/3.2.1 /cm/shared/modulefiles/singularity/3.6.3
vi /cm/shared/modulefiles/singularity/3.6.3
ll /cm/shared/apps/singularity/3.6.3

该提问来源于开源项目:hpcng/singularity

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

7条回答

  • weixin_39972151 weixin_39972151 4月前
    • if you are able could you take a look at the PR #5670 to see if it works for you. It'll set SINGULARITY_BIND in the container to be the list of binds from a SINGULARITY_BIND env var outside, plus any --bind/-B flags.
    点赞 评论 复制链接分享
  • weixin_39889642 weixin_39889642 4月前

    Thanks for the PR! I have compiled singularity and tested your version, it indeed solves the Issue:

    bash
    # Works as intended
    $ export SINGULARITY_BIND=/tmp
    $ singularity exec MyFavoriteContainer.sif echo $SINGULARITY_BIND
    /tmp
    
    # Also works as intended because does not modify $SINGULARITY_BIND in any way
    $ export SINGULARITY_BIND=/tmp,/lalala
    $ singularity exec MyFavoriteContainer.sif echo $SINGULARITY_BIND
    WARNING: skipping mount of /lalala: no such file or directory
    /tmp,/lalala
    
    点赞 评论 复制链接分享
  • weixin_39889642 weixin_39889642 4月前

    However, the $SINGULARITY_BIND variable inside the container does not contain values passed through --bind/-B as described in your MR. It's not a functionality I need, and I don't know if this feature was available in the past, but I thought I should let you know:

    bash
    # Does not add values passed to `--bind`
    $ export SINGULARITY_BIND=/tmp,/lalala
    $ singularity exec --bind /cdrom:/cdrom MyFavoriteContainer.sif echo $SINGULARITY_BIND
    WARNING: skipping mount of /lalala: no such file or directory
    /tmp,/lalala
    
    # Even if $SINGULARITY_BIND was initially empty
    unset SINGULARITY_BIND
    singularity exec  --bind /cdrom:/cdrom MyFavoriteContainer.sif echo $SINGULARITY_BIND
    
    
    点赞 评论 复制链接分享
  • weixin_39972151 weixin_39972151 4月前
    • the PR is adding the --bind flag binds as:

    • It's convenient to do so with the code paths that now exist

    • SINGULARITY_BIND in the container then contains a list of all the user requested binds, whether by env var or flag - which seems useful for the use-case I've seen, where SINGULARITY_BIND is inspected in the container to ascertain whether the user bound a required data dir etc.

    Can you elaborate on how you were using $SINGULARITY_BIND inside the container?

    点赞 评论 复制链接分享
  • weixin_39889642 weixin_39889642 4月前

    Your PR is not functional for point 2 in my tests, see details above.

    In our use-case, we currently use $SINGULARITY_BIND within the container because our Python container outputs some scripts which contain calls to other containers and $SINGULARITY_BIND values have to be passed into those scripts.

    点赞 评论 复制链接分享
  • weixin_39972151 weixin_39972151 4月前

    Your PR is not functional for point 2 in my tests, see details above.

    Ahh - sorry - I misread this - I glanced though and thought you were showing output from older Singularity there.

    The PR does work... it's that with your echo $SINGULARITY_BIND the shell is resolving $SINGULARITY_BIND outside of the container. You need to do something like this to make that variable expansion happen in a shell in the container, so you see the value inside the container:

    
    $ export SINGULARITY_BIND=/tmp,/lalala
    
    # This shows the real value in the container
    $ singularity exec --bind /srv alpine_latest.sif sh -c 'echo $SINGULARITY_BIND'
    /srv,/tmp,/lalala
    
    # This shows the value outside, in my host shell - because $SINGULARITY_BIND
    # is resolved outside, before singularity runs
    $ singularity exec --bind /srv alpine_latest.sif echo $SINGULARITY_BIND
    /tmp,/lalala
    
    点赞 评论 复制链接分享
  • weixin_39889642 weixin_39889642 4月前

    Thanks for pointing that out!

    点赞 评论 复制链接分享