Skip to content

Europa: docker.#Run entrypoint behavior does not seem to match docker run cli #1555

Closed

Description

@talentedmrjones

The default behavior of docker run when no --entrypoint is provided, and ENTRYPOINT[] has not been overridden is to use /bin/sh -c. This allows CMD to be easily processed through the shell. Overridding entrypoint allows for bootstrapping scripts to do setup, perhaps export some necessary env vars, then exec "$@" as one example.

The current implementation does not seem to allow providing a direct entrypoint to use besides the one in image config. From docker.#Run._exec:

if cmd != _|_ {
  args: [cmd.name] + cmd._flatFlags + cmd.args
}
if cmd == _|_ {
  args: list.Concat([
    if _image.config.entrypoint != _|_ {
      _image.config.entrypoint
    },
    if _image.config.cmd != _|_ {
      _image.config.cmd
    },
  ])
}

In the above code, cmd is always exec'd without a shell which is fine, but the only way to use entrypoint and arbitrary commands together is to set them in the image config which by the nature of immutable configs you must do so via engine.#Set which can be verbose and confusing.

It seems that docker.#Run should provide an entrypoint field; if this field is _|_ then image.config.entrypoint is used instead, and if that is _|_ then docker.#Run defaults to what? /bin/sh -c ? or nothing?

Activity

  1. talentedmrjones commented on Feb 4, 2022

    @talentedmrjones
    Author

    One use case for a custom entrypoint is from my current universe/aws where I want to bootstrap the configuration so that any command that leverages the AWS SDK (including the CLI, CDK, custom python/boto3 scripts, can execute and gain access to credentials and config:

    /scripts/bootstrap.sh

    #!/bin/sh
    if [ -f /run/secrets/accessKeyId ]; 
      export AWS_ACCESS_KEY_ID=$(cat /run/secrets/accessKeyId)
    fi
    if [ -f /run/secrets/secretAccessKey ]; then
      export AWS_SECRET_ACCESS_KEY=$(cat /run/secrets/secretAccessKey)
    fi
    if [ -f /run/secrets/sessionToken ]; then
      export AWS_SESSION_TOKEN=$(cat /run/secrets/sessionToken)
    fi
    if [ -f /aws/config ]; then
      export AWS_CONFIG_FILE="/aws/config"
    fi
    
    exec "$@"

    This would then allow any arbitrary command to be execute after the config is setup. It's meant to be a convenience to the user so they can just provide their command.

    To use (abridged version):

    mounts: scripts: dest: '/scripts'
    entrypoint: '/scripts/bootstrap.sh'
    cmd: name: string // any command that uses an AWS SDK that pulls config from those env vars
  2. helderco commented on Mar 15, 2022

    @helderco
    Contributor

    The way I understand it, the shell is only added to entrypoint when you use the shell-form in a Dockerfile. It's the same with CMD. In the spec, both end up as arrays. And when running, one is just appended to the other.

    In effect, in dagger, you could use command: name as the entrypoint, but you're right we should have a field that overrides the entrypoint in the image.

    To answer the last question, if no entrypoint is set either in #ImageConfig or docker.#Run, then nothing should be prepended to dagger.#Exec: args.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions