Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

singularity run and execute command

I know how to run a singularity:

singularity run /mn/sarpanitu/singularity/test/fenics-and-more.img

Is there a way to do a one line (or more) to run the previous command, and then in singularity run echo "hi there" ? (Of course, I will use something more complex than hi there in production). Once this is done, I want my singularity to still be well and alive for interactive use.

So something like the intent of:

singularity run /mn/sarpanitu/singularity/test/fenics-and-more.img -bash-command echo "hi there"

or

singularity run /mn/sarpanitu/singularity/test/fenics-and-more.img -run-script-at-startup script.sh
like image 715
Zorglub29 Avatar asked Apr 13 '26 07:04

Zorglub29


2 Answers

Use exec, for executing a command within container instead of run. Add the shell and the script as parameters.

singularity exec /mn/sarpanitu/singularity/test/fenics-and-more.img /bin/sh script.sh

Also, add the execution of parameter as a default runtime command in the runscript part.

%runscript
  exec "$@"
like image 78
Sergi Pérez Labernia Avatar answered Apr 14 '26 22:04

Sergi Pérez Labernia


This is very related to the following question: bash script to perform action in a singularity container it opens . Solution is posted there, basically using the -c option and spawning a bash console.

like image 39
Zorglub29 Avatar answered Apr 14 '26 21:04

Zorglub29