Docker run override entrypoint with shell script which accepts arguments

I have entrypoint shell script which accepts arguments -a -b.

I have working docker-compose.yml file where I override tomcat’s entrypoint with instruction:

  • Performance of IBM Containers Volumes
  • What does docker use for (image) versioning?
  • How to run Docker container and watch the logs in one single command
  • Prevent request too quickly in bash
  • docker cp the content of a folder
  • Dbus running inside Docker container
  • entrypoint: /usr/local/tomcat/entrypoint.sh -a param1 -b param2
    

    What is docker run alternative?

    docker run --entrypoint "/usr/local/tomcat/entrypoint.sh -a param1 -b param2" tomcat:jre8
    

    does not work

    I get:

    docker: Error response from daemon: 
    invalid header field value "oci runtime error: container_linux.go:247: 
    starting container process caused \"exec:
    \\\"/usr/local/tomcat/entrypoint.sh -a param1 -b param2\\\": 
    stat /usr/local/tomcat/entrypoint.sh -a param1 -b param2: 
    no such file or directory\"\n".
    

    FYI:

    docker run --entrypoint "/usr/local/tomcat/entrypoint.sh" tomcat:jre8
    

    works from Docker point of view, but obviously script fails

  • AWT error while trying to build Jenkins Docker image based on Alpine -
  • Dockerfile: create ENV variable that a USER can see?
  • How do I attach VisualVM to a simple Java process running in a Docker container
  • Build container with docker-compose, but run /etc/bash with -it option later?
  • Can't create Docker network
  • AWS S3 Elastic Beanstalk Docker - /dev/fus: Operation not permitted
  • 2 Solutions collect form web for “Docker run override entrypoint with shell script which accepts arguments”

    It is because of the quotes you’re using around your command.

    When you run docker run --entrypoint "/usr/local/tomcat/entrypoint.sh -a param1 -b param2" tomcat:jre8 Docker treats whatever is within those quotes as a single script file.

    As you can see from the error:

    stat /usr/local/tomcat/entrypoint.sh -a param1 -b param2: 
    no such file or directory\"\n".
    

    It’s trying to perform a stat on the file before running it, so it knows if it exists.

    Place the arguments to your entrypoint at the end of your docker command like so:

    docker run --entrypoint <entrypoint.sh> <image:tag> <arg1> <arg2> <arg3>
    

    Your command becomes:

    docker run --entrypoint /usr/local/tomcat/entrypoint.sh tomcat:jre8 -a param1 -b param2 
    

    Have a look at the code snippets in the official documentation:

    The ENTRYPOINT of an image is similar to a COMMAND because it
    specifies what executable to run when the container starts

    https://docs.docker.com/engine/reference/run/#/entrypoint-default-command-to-execute-at-runtime

    I am not sure you can do that according to the official docker documentation:

    Note: you can override the ENTRYPOINT setting using –entrypoint, but
    this can only set the binary to exec (no sh -c will be used).

    https://docs.docker.com/engine/reference/builder/#/environment-replacement

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.