The image you are using will have its own CMD
defined - when you do docker run <image>
(or use it in your compose file), this is what will be executed.
(in fact, you can modify the command in the compose file if you like using command:
- syntax reference here)
A solution
When you create a new Dockerfile that is built FROM <image>
, you don't inherit CMD
. Therefore, if you want to run the original command, you need to find out what it was.
Sadly, this is always going to entail some searching. For example, these docs give you some information about the elasticsearch image:
Entrypoint: ["/bin/tini","--","/usr/local/bin/docker-entrypoint.sh"]
Command: ["eswrapper"]
To me, this seems to suggest the full startup sequence is /bin/tini -- /usr/local/bin/docker-entrypoint.sh eswrapper
.
Perhaps the best solution is to create a small shell script that executes your custom command, followed by this startup command, and invoke that script via a new CMD
?
(This is a bit less verbose than trying to cram the separate commands into CMD
)
Alternative solution
Another suggestion is that in the example you give, the two commands seem to be decoupled from each other - i.e. there's actually no reason to run them in the same container, it's just that one has to run before the other.
If that's really the case (maybe it isn't in practice), you may want to run the off-the-shelf image via compose, but specify that it depends_on another container that will simply run the command.
This probably isn't suitable if the command is sleep
(the dependency is on the container starting, not running to completion), but if it's echo
than it might be okay.