Reputation: 5823
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
).
Upvotes: 1
Views: 1577
Reputation: 9402
You could use an intermediate build image that triggers an ONBUILD
statement from your original Dockerfile, see: https://docs.docker.com/engine/reference/builder/#/onbuild
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 configuration.
Regarding CMD and ENTRYPOINT, see: https://docs.docker.com/engine/reference/builder/#understand-how-cmd-and-entrypoint-interact
CMD
or ENTRYPOINT
commands.ENTRYPOINT
should be defined when using the container as an
executable.CMD
should be used as a way of defining default arguments for an
ENTRYPOINT
command or for executing an ad-hoc command in a
container.CMD
will be overridden when running the container with alternative
arguments.Upvotes: 1
Reputation: 2555
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
./run_binary
/bin/sh -c "$@"
Upvotes: 2