What is ENTRYPOINT in Docker?

Overview

In a Dockerfile, we use the ENTRYPOINT instruction to provide executables that will always execute when the container is launched.

Unlike CMD commands, even when the container is running with the specified command line parameters, ENTRYPOINT instructions can’t be ignored or overridden.

Syntax

The ENTRYPOINT function has two forms:

  1. The exec form, which is the preferred form:
ENTRYPOINT ["executable", "param1", "param2"]
  1. The shell form:
ENTRYPOINT command param1 param2

Example

Consider the below Dockerfile.

FROM ubuntu:latest
ENTRYPOINT ["echo", "Hello, Educative"]

Build a Docker image using the above Dockerfile.

docker build -t ubuntu-test.

When creating the image, the Docker daemon searches for the ENTRYPOINT instruction and identifies it as the default application that will execute with or without command-line input.

The next step is to run the Docker image in a Docker container.

docker run ubuntu-test

When the container is run without command-line arguments, the ENTRYPOINT instruction is executed, and Hello, Educative is echoed.

When the container is run with the command-line parameters, the arguments are appended as arguments for the ENTRYPOINT instruction.

docker run ubuntu-test uname -a

The output will be:

Hello, Educative Darwin Abhis-MacBook-Air.local 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:21 PDT 2021; root:xnu-7195.141.6~3/RELEASE_X86_64 x86_64