Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default Docker entrypoint

Tags:

docker

sh

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?

like image 285
Eugene Dounar Avatar asked Jun 04 '16 20:06

Eugene Dounar


People also ask

What is ENTRYPOINT of Docker image?

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.

What is CMD and ENTRYPOINT in Docker?

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.

Can I use both ENTRYPOINT and CMD?

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.

Can we have 2 ENTRYPOINT in Dockerfile?

According to the documentation however, there must be only one ENTRYPOINT in a Dockerfile.


1 Answers

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 /" 
like image 143
Matt Avatar answered Sep 21 '22 16:09

Matt