ScanSkill

ENTRYPOINT

It allows configuring a container that will run as an executable. It is used to run when the container starts.

Command-line arguments to docker run <image> will be appended after all elements in an exec form ENTRYPOINT and will override all elements specified using CMD. If multiple Entrypoint, then only the last ENTRYPOINT instruction in the Dockerfile will have an effect.

Syntax

# *exec* form - preferred
ENTRYPOINT ["<executable>", "<param1>", "<param2>"]

# *shell* form
ENTRYPOINT <command> <param1> <param2>

Example

  • Exec form
FROM alpine:latest

RUN echo $HOME

ENTRYPOINT ["/bin/echo", "Print ENTRYPOINT instruction of Exec Form"]
  • Shell form
FROM alpine:latest

RUN echo $HOME

ENTRYPOINT /bin/echo 'print ENTRYPOINT instruction of shell form'

Also, you can override the ENTRYPOINT instruction by using --entrypoint flag for the running container.

Now run the container:

# Build Image
docker build -t exampleImage .

# Run the Image, it will print Print ENTRYPOINT instruction of Exec Form
docker container run exampleImage

# Override ENTRYPOINT: it will print 'Override ENTRYPOINT Instruction' replacing above.
docker run --entrypoint "/bin/echo" exampleImage "Override ENTRYPOINT Instruction"