I am creating an image from another image that set a specific entrypoint. However I want my image to have default one. How do I reset the ENTRYPOINT?
I tried the following Dockerfile:
FROM some-image ENTRYPOINT ["/bin/sh", "-c"]
Unfortunately it doesn't work like the default entrypoint as it need the command to be quoted.
docker run myimage ls -l / # "-l /" arguments are ignored file1 file2 file3 # files in current working directory docker run myimage "ls -l /" # works correctly
How do I use commands without quoting?
Docker ENTRYPOINT In Dockerfiles, an ENTRYPOINT instruction is used to set executables that will always run when the container is initiated. Unlike CMD commands, ENTRYPOINT commands cannot be ignored or overridden—even when the container runs with command line arguments stated.
When we have specified the ENTRYPOINT instruction in the executable form, it allows us to set or define some additional arguments/parameters using the CMD instruction in Dockerfile. If we have used it in the shell form, it will ignore any of the CMD parameters or even any CLI arguments.
Example of using CMD and ENTRYPOINT togetherIf both ENTRYPOINT and CMD are present, what is written in CMD is executed as an option of the command written in ENTRYPOINT. If an argument is added at the time of docker run , the contents of CMD will be overwritten and the ENTRYPOINT command will be executed.
According to the documentation however, there must be only one ENTRYPOINT in a Dockerfile.
To disable an existing ENTRYPOINT
, set an empty array in your docker file
ENTRYPOINT []
Then your arguments to docker run
will exec as a shell form CMD would normally.
The reason your ENTRYPOINT ["/bin/sh", "-c"]
requires quoted strings is that without the quotes, the arguments to ls
are being passed to sh
instead.
Unquoted results in lots of arguments being sent to sh
"/bin/sh", "-c", "ls", "-l", "/"
Quoting allows the complete command (sh -c
) to be passed on to sh
as one argument.
"/bin/sh", "-c", "ls -l /"
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