I have a dockerfile which ends
ENTRYPOINT ["sh"]
CMD ["runscript.sh"]
I can run docker with an argument (a shell script) that overrides "runscript.sh" (if i wish). Note: the shell scripts are provided by a --bind
mount
I am translating my Dockerfile to a Singularity recipe. From my understanding i can replicate this ENTRYPOINT/CMD functionality using the "%startscript" label. I am trying:
%startscript
exec "$@"
then run an instance of the container using
singularity instance start --bind /hostpath:/containerpath model.sif instancename script.sh
When i do this i get the message:
/.singularity.d/startscript: 4: exec: script.sh: not found
I know i am doing this all wrong, but cant seem to work out what.
Note: if i replace exec "$@"
with ./script.sh
then the script is executed but i am limited to having a script with this name. I want the flexibility to pass any named script.
2
Answers
You need to use
and not
Then you can pass an argument to run command which will be used in place of the default value in the recipe,
eg. in the recipe file
then use either
or
depending on whether you want to run the default container script or the "newscript"
In your original Dockerfile:
ENTRYPOINT
CMD
includes some sort of path, likeCMD ["./runscript.sh"]
#!/bin/sh
chmod +x runscript.sh
, and check that change into source controlThis is the same set of steps you’d need to do to be able to run
./runscript.sh
on the host system, without Docker, and the same rules apply.In the script you show, you’re just running
exec "$@"
, presumably as an entrypoint script being passed theCMD
as arguments. Your original Dockerfile prepended whateverCMD
it was given withsh
(theENTRYPOINT
value), but this wrapper doesn’t, and that’s why you’re getting different behavior.In general I wouldn’t encourage splitting out the name of a language interpreter into
ENTRYPOINT
. I prefer a pattern ofCMD
being a complete command, which is compatible with the sort of entrypoint wrapper script you show. There’s also a pattern ofENTRYPOINT
being a complete command andCMD
its arguments (Kubernetes calls these optionscommand:
andargs:
). What you have here is kind of a half way, though: if you overrideCMD
then you must repeat the program name, but you can only actually run programs that are implemented as shell scripts.