Dockerfile run entrypoint before shell entrypoint

I’m wanting to do some last minute setup on run before passing arguments to the shell entrypoint, to accomplish this I have the following in mind.

ENTRYPOINT ./run_binary ${args}; /bin/sh -c
CMD ./run_binary

However, by doing this, it doesn’t seem that any CMD arguments make it to the shell entrypoint. Is there a way around this? I’m just wanting to run a setup step on a binary before handing back control to the shell entrypoint (and then to the USER via CMD).

  • How to launch an app via Docker on every Pull Request?
  • How to Create a Container in docker remote api? (go-dockerclient)
  • Docker: Error pulling image, executable file not found in $PATH
  • deisctl list command raises a timeout error what am I doing wrong
  • Docker MYSQL '[2002] Connection refused'
  • Cannot use process substitution during docker build because bash goes into posix mode
  • Running docker-compose with mysql and own docker container
  • Passing variables as arguments to docker container
  • Seeding sclorg/mariadb container
  • Adding sphinx container docker-compose shows an error
  • How can I write Dockerfile for Yesod? “RUN yesod init -n myApp -d postgresql” didn't work as expected
  • Ember in docker with nginx can't reach server container
  • 2 Solutions collect form web for “Dockerfile run entrypoint before shell entrypoint”

    You could use an intermediate build image that triggers an ONBUILD statement from your original Dockerfile, see:

    The ONBUILD instruction adds to the image a trigger instruction to be
    executed at a later time, when the image is used as the base for
    another build. The trigger will be executed in the context of the
    downstream build, as if it had been inserted immediately after the
    FROM instruction in the downstream Dockerfile.

    This is useful if you are building an image which will be used as a
    base to build other images, for example an application build
    environment or a daemon which may be customized with user-specific

    Regarding CMD and ENTRYPOINT, see:

    1. Dockerfile should specify at least one of CMD or ENTRYPOINT
    2. ENTRYPOINT should be defined when using the container as an
    3. CMD should be used as a way of defining default arguments for an
      ENTRYPOINT command or for executing an ad-hoc command in a
    4. CMD will be overridden when running the container with alternative

    CMD becomes a list of arguments to send to ENTRYPOINT when both are specified, see the manual, so that’s not the way to go

    but you could use a .sh script as ENTRYPOINT, that first executes your binary command and then forwards the received arguments to a shell

    I haven’t tried it but something along the lines of

    /bin/sh -c "$@"
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.