Hi, thanks for the answer. I tried what you suggested, but it turns out that the working dir is not preserved. I'll try to make it clearer with a reproducible example:
singularity pull library://default/alpine
mkdir test
cd test
singularity exec -H ..:/proj ../alpine_latest.sif pwd
#> /proj
expected:
#> /proj/test
So the problem I have is that if I set the home directory, the current working directory is not preserved but set to the home directory.
There is the option of using --pwd:
singularity exec -H ..:/proj --pwd /proj/test ../alpine_latest.sif pwd
#> /proj/test
But the problem here is that I need to figure out the inside-container path /proj/test by myself with the bash script I provide to my colleagues. I have to consider not only the mount to /home, but also to other directories that are mounted with --bind (read-only analysis input data). An example is below. But that is essentially rebuilding the singularity file namespacing logic in bash; I want to avoid that as it will be fragile and bug-ridden. Can singularity start with the current WD translated to the in-container path, taking into account also all other bind mounts of the container, not only /home?
cd /home/user/test
ls
#> alpine_latest.sif
mkdir home home/dir1 external_files
sing_pwd(){
# mount project folder and external files to /proj and /ext
# and run "pwd"
singularity exec \
-H /home/user/test:/proj \
-B /home/user/external_files:/ext \
/home/user/test/alpine_latest.sif \
pwd
}
cd /home/user/test/home/dir1
sing_pwd
#> /proj/dir1 # (expected; actual output is: /proj)
cd /home/user/test/external_files
sing_pwd
#> /ext # (expected; actual output is: /proj)
Cheers,
Moritz