From 07e954d11b8bc7e0e1dbe6994e132fea39294ec7 Mon Sep 17 00:00:00 2001 From: Andy Neff Date: Wed, 16 Oct 2019 11:19:18 -0400 Subject: [PATCH] Make the CMD behave more like docker Signed-off-by: Andy Neff --- docker2singularity.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/docker2singularity.sh b/docker2singularity.sh index 49b9c6f..2ea70d9 100755 --- a/docker2singularity.sh +++ b/docker2singularity.sh @@ -258,12 +258,15 @@ if [[ $WORKINGDIR != '""' ]]; then fi # First preference goes to both entrypoint / cmd, then individual -if [ -n "$ENTRYPOINT" ] && [ -n "$CMD" ]; then - echo exec "$ENTRYPOINT" "$CMD" '"$@"' >> $build_sandbox/.singularity.d/runscript; +if [ -n "$CMD" ]; then + echo 'if [ $# = 0 ]; then' >> $build_sandbox/.singularity.d/runscript + # Only add the entrypoint if it's not null + echo \ \ exec ${ENTRYPOINT:+"$ENTRYPOINT"} "$CMD" >> $build_sandbox/.singularity.d/runscript; + echo "else" >> $build_sandbox/.singularity.d/runscript + echo \ \ exec ${ENTRYPOINT:+"$ENTRYPOINT"} '"$@"' >> $build_sandbox/.singularity.d/runscript; + echo "fi" >> $build_sandbox/.singularity.d/runscript elif [ -n "$ENTRYPOINT" ]; then echo exec "$ENTRYPOINT" '"$@"' >> $build_sandbox/.singularity.d/runscript; -elif [ -n "$CMD" ]; then - echo exec "$CMD" '"$@"' >> $build_sandbox/.singularity.d/runscript; fi chmod +x $build_sandbox/.singularity.d/runscript;