This is one of the big differences between docker and singularity.
In docker, the working directory is set in the Dockerfile
with WORKDIR /some/path
or the -w /some/path
command line argument. Otherwise, it uses the default of /
.
With singularity however, your home directory (or current directory, on older versions) on the host machine is mounted in and used as the working directory inside the container. You can use the --pwd
flag to override this.
So given the Dockerfile:
FROM debian:buster-slim
COPY main.sh test.sh /
Running with docker:
$ docker run --rm myuser/mydocker:1.0 ./main.sh
Executing main.sh
Executing test.sh
$ docker run --rm myuser/mydocker:1.0 pwd
/
In singularity:
# note the full path of the file that isn't found
$ singularity exec -e mydocker.sif ./main.sh
FATAL: stat /home/tsnowlan/main.sh: no such file or directory
# does NOT match the WORKDIR from the Dockerfile
$ singularity exec -e mydocker.sif pwd
/home/tsnowlan
# use full path to the script
# BUT still executing from $HOME so `./test.sh` is resolves to `$HOME/test.sh`
$ singularity exec -e mydocker.sif /main.sh
Executing main.sh
/main.sh: line 4: ./test.sh: No such file or directory
# tell singularity to run from /
$ singularity exec -e --pwd / mydocker.sif ./main.sh
Executing main.sh in
Executing test.sh
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…