docker2singularity icon indicating copy to clipboard operation
docker2singularity copied to clipboard

Make the CMD behave more like docker

Open andyneff opened this issue 6 years ago • 5 comments

The way the current script was written, if you have a when you do singularity run myimage.sif foo bar and the docker had a CMD defined, the singularity runscript will run CMD foo bar instead of foo bar. It should only run CMD when no command args are specified, to match docker and singularity build myimage.sif docker://myorg/myimage behavior.

If you accept this PR, what is the best way to get it into the other version branches? Do I need to create a PR to each branch version, or is that something the owners take care of?

andyneff avatar Oct 16 '19 15:10 andyneff

There was a lot of contention around this (see https://github.com/singularityhub/docker2singularity/issues/49) so I'm going to ask for @rgov input before making any changes. Generally we need to respect both CMD and ENTRYPOINT and account for all the cases of having / not having each defined (which I think the current implementation does).

vsoch avatar Oct 16 '19 16:10 vsoch

Just as another data point, when I ran singularity build redis.sif docker://redis and look at the runscript, I see

# ENTRYPOINT and CMD - run ENTRYPOINT with CMD as default args
# override with user provided args
if [ $# -gt 0 ]; then
    SINGULARITY_OCI_RUN="${OCI_ENTRYPOINT} ${CMDLINE_ARGS}"
else
    SINGULARITY_OCI_RUN="${OCI_ENTRYPOINT} ${OCI_CMD}"
fi

Which agrees with my PR and docker's behavior

andyneff avatar Oct 16 '19 17:10 andyneff

@andyneff is correct:

If the image also specifies an ENTRYPOINT [in the Dockerfile] then the CMD [in the Dockerfile] or COMMAND [from the command line] get appended as arguments to the ENTRYPOINT.

rgov avatar Oct 16 '19 17:10 rgov

However, is the assignment of SINGULARITY_OCI_RUN safe here? What does it do to arguments that contain spaces, quotes, escaping, etc?

Edit: Ok I understand, this is going in the other direction.

rgov avatar Oct 16 '19 17:10 rgov

@rgov that was a snippet from the other way to create singularity images from docker. I believe it has already properly quote escaped the string, and then eval set's it, so that they are set back to the the command line arguments $1 $2 ..., then finally exec $@

I was just using that as evidence for this PR, saying this should do what singularity build already does, as it is what is "expected behavior" for docker images/community.

andyneff avatar Oct 16 '19 18:10 andyneff