Automatically source different setup.bash files when a starting singularity image
Problem description
I am trying to source the setup.bash file
and other setup.bash
files automatically when shelling into a singularity image. I, therefore, added the following line to my singularity recipe file:
%environment
## Source ros setup file ##
. /opt/ros/kinetic/setup.sh
After building the singularity image this source command ends up in the *90-enviroments.sh
script, which is then sourced when the singularity shell is opened. Unfortunately, the environmental variables that are supposed to be set when sourcing the setup.bash file
are not available when I shell into the container using the singularity shell --nv container.simg
command. For example, when I am trying to use the roslaunch
command I get the following error:
bash: roslaunch: command not found
I found the following solution on StackOverflow but I was hoping there is something similar to the runscript
argument that enables me to source files when shelling into a singularity container.
Version of Singularity:
3.0.3
Expected behavior
I expected the /opt/ros/kinetic/setup.bash
file to be sourced when the container is loaded using shell --nv container.simg
Actual behavior
Although the source command ends up in the *90-enviroments.sh
script none of the enviromental variables that are supposed to be added to my workspace when sourcing the /opt/ros/kinetic/setup.bash
file is available in my workspace. These commands appear to be available again when I run the bash
command inside the singularity image. I, therefore, suspect that the singularity image uses a slightly different /bin/bash shell. The echo $SHELL
command both has /bin/bash
as an output in both the singularity shell and the bash shell running inside the singularity image.
Steps to reproduce the behaviour
Add one of the following source commands to the %enviroment
section of the singularity recipe file:
. /file_you_you_want_to_source.sh
source /file_you_you_want_to_source.sh
bash -c "source /file_you_you_want_to_source.sh"
sh -c "source /file_you_you_want_to_source.sh"
bash -c ". /file_you_you_want_to_source.sh"
sh -c ". /file_you_you_want_to_source.sh"
EDIT:
I migrated my issue to the singularity Github issue page
Two observations:
@gvdhoorn Thanks for your comment I updated the question and also migrated my question to the singularity GitHub issues page.
if you did, then please post a link to that issue here in a comment so we can keep things connected.
This issue has been migrated to the singularity GitHub issues page
The official O(S)R(F) Docker images use
ENTRYPOINT
for this (here fi), with this script.The Singularity documentation discusses how
ENTRYPOINT
andCMD
are converted / can be used in Singularity images and containers: Singularity and Docker: Building images for Singularity from Docker Registries - Working with Definition Files - Directing Execution.@gvdhoorn Thanks a lot for pointing me to the right documentation. I now see I had a wrong understanding of when to use the
run
,shell
and start commands. After thoroughly going to the documentation and testing out different options I came to the following conclusion on what to do in my case:%runscript
and%startscript
in my recipe file and following interacting with the created container using the run and start instance commands. This gives me full control over whether I want to use theENTRYPOINT
andCMD
options supplied by the docker file or use my own run/startup commands.