ImagoXV / NanoASV

NanoASV official repo
GNU General Public License v3.0
3 stars 0 forks source link

Singularity keeps looking for bin outside the container #68

Closed ImagoXV closed 2 months ago

ImagoXV commented 2 months ago

This drives me crazy.

On the IFB cluster, NanoASV running with singularity :

/shared/software/modules/4.6.1/init/bash: line 37: /usr/bin/tclsh: No such file or directory

The whole purpose of a container is to NOT LOOK OUTSIDE OF IT isn't it ?

ImagoXV commented 2 months ago

Looking at $PATH :

SINGULARITY VERSION

Singularity> echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

DOCKER

root@69d16b98cdbd:/# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

I don't get it

ImagoXV commented 2 months ago

I got it, singularity injects env into the container. I'll add an explicit portion of script to get rid of that and that should do the trick.

# Unset non-essential variables to deal with singularity eating local env variables
unset $(env | grep -vE '^(HOME|USER$|SHELL|PWD|PATH|LD_LIBRARY_PATH|TMP|TMPDIR|LANG|LC_)' | cut -d= -f1)

# Set essential variables explicitly
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export LD_LIBRARY_PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ImagoXV commented 2 months ago

So I still had problems because of bash functions being injected within the container. This had consequences regarding some of the called librairies. So I manually delete bash functions from the environment at launch.

# Unset non-essential variables to deal with singularity eating local env variables
unset $(env | grep -vE '^(HOME|USER$|PWD|TMP|LANG|LC_)' | cut -d= -f1)
# Unset all BASH_FUNC_* variables
for func in $(env | grep -o '^BASH_FUNC_.*=' | sed 's/=$//'); do
    unset $func
done
# Set essential variables explicitly
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export LD_LIBRARY_PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

If anyone has a better solution, I'm taking it