Skip to main content
InterviewHubPRO
Section Overview
Q4

Question 4 of 50

Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

8%
Docker & Containers (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

What is the difference between `CMD` and `ENTRYPOINT` in Docker?

junior LevelMost AskedCode ExampleDocker & Containers

In Simple Words:

  • ENTRYPOINT: Defines the core executable that will always run when the container starts. It turns the container into an executable CLI tool.
  • CMD: Provides default arguments or parameters to the ENTRYPOINT. If ENTRYPOINT is not defined, CMD acts as the default command.
  • Overriding behavior:
    • CMD is easily overridden by passing arguments at the end of docker run.
    • ENTRYPOINT cannot be overridden unless you explicitly pass the --entrypoint flag.
dockerfile
# Pattern: Combining ENTRYPOINT and CMD
ENTRYPOINT ["curl"]
CMD ["https://api.github.com"]

# Running without args: runs 'curl https://api.github.com'
$ docker run my-curl-tool

# Overriding CMD with custom URL: runs 'curl https://example.com'
$ docker run my-curl-tool https://example.com