The documentation for the run
command follows the following syntax:
docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]
however I've found at times that I want to pass a flag to [COMMAND]
.
For example, I've been working with this image, where the [COMMAND]
as specified in the Dockerfile is:
CMD ["/bin/bash", "-c", "/opt/solr/bin/solr -f"]
Is there any way to tack on flags to "/opt/solr/bin/solr -f"
so that it's in the form "/opt/solr/bin/solr -f [-MY FLAGS]"
?
Do I need to edit the DockerFile or is there some built in functionality for this?
There is a special directive ENTRYPOINT
which fits your needs. Unlike CMD
it will add additional flags at the end of your command.
For example, you can write
ENTRYPOINT ["python"]
and run it with
docker run <image_name> -c "print(1)"
Note, that this only will work if you write command in exec
form (via ["...", "..."]
), otherwise ENTRYPOINT
will invoke shell
and pass your args there, not to your script.
More generally, you can combine ENTRYPOINT
and CMD
ENTRYPOINT ["ping"]
CMD ["www.google.com"]
Where CMD
means default args for your ENTRYPOINT
. Now you can run both of
docker run <image_name>
docker run <image_name> yandex.ru
and only CMD
will be replaced.
Full reference about how ENTRYPOINT
and CMD
interact can be found here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With