Skip to content

Commit 07e954d

Browse files
committed
Make the CMD behave more like docker
Signed-off-by: Andy Neff <[email protected]>
1 parent d5a96e9 commit 07e954d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

docker2singularity.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,15 @@ if [[ $WORKINGDIR != '""' ]]; then
258258
fi
259259

260260
# First preference goes to both entrypoint / cmd, then individual
261-
if [ -n "$ENTRYPOINT" ] && [ -n "$CMD" ]; then
262-
echo exec "$ENTRYPOINT" "$CMD" '"$@"' >> $build_sandbox/.singularity.d/runscript;
261+
if [ -n "$CMD" ]; then
262+
echo 'if [ $# = 0 ]; then' >> $build_sandbox/.singularity.d/runscript
263+
# Only add the entrypoint if it's not null
264+
echo \ \ exec ${ENTRYPOINT:+"$ENTRYPOINT"} "$CMD" >> $build_sandbox/.singularity.d/runscript;
265+
echo "else" >> $build_sandbox/.singularity.d/runscript
266+
echo \ \ exec ${ENTRYPOINT:+"$ENTRYPOINT"} '"$@"' >> $build_sandbox/.singularity.d/runscript;
267+
echo "fi" >> $build_sandbox/.singularity.d/runscript
263268
elif [ -n "$ENTRYPOINT" ]; then
264269
echo exec "$ENTRYPOINT" '"$@"' >> $build_sandbox/.singularity.d/runscript;
265-
elif [ -n "$CMD" ]; then
266-
echo exec "$CMD" '"$@"' >> $build_sandbox/.singularity.d/runscript;
267270
fi
268271

269272
chmod +x $build_sandbox/.singularity.d/runscript;

0 commit comments

Comments
 (0)